rwset

package
v1.0.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 7, 2020 License: GPL-3.0, GPL-3.0 Imports: 15 Imported by: 0

README

TxSimulator设计思路

  1. 开始创建一个新单元时创建TxMgr实例
  2. 一个单元中包含多笔系统合约的Invoke时,每个Tx使用一个新的TxSimulator实例,新的实例基于DAG或者上一个TxSimulator实例。 交易完成后需要调用TxSimulator的Done或者Rollback
  3. 单元创建完毕时,需要关闭所有TxSimulator和对应的TxMgr

连续交易涉及问题

除了合约的读写集,还涉及到合约相关的UTXO,如果是连续交易,下一个合约应该可以用上一个合约的写集和生成的UTXO 因为涉及到合约手续费不够或者合约错误,导致写集和UTXO回滚,所以应该提供清除某RequestId的写集和UTXO的方法。 为了防止双花,一个连续交易中,上一个Tx用掉的UTXO,下一个Tx不能再使用,但可以使用上一个Tx生成的新UTXO。 关于读集的版本问题,如果AB是连续交易,B读了A产生的写集,B的读集里面的Version就应该是空?

Documentation

Overview

  • @author PalletOne core developers <dev@pallet.one>
  • @date 2018-2020

Package rwset is a generated GoMock package.

  • @author PalletOne core developers <dev@pallet.one>
  • @date 2018-2020

Index

Constants

This section is empty.

Variables

View Source
var ChainId = "palletone"

Functions

This section is empty.

Types

type IDataQuery added in v1.0.6

type IDataQuery interface {
	IStateQuery
	UnstableHeadUnitProperty(asset modules.AssetId) (*modules.UnitProperty, error)
	GetGlobalProp() *modules.GlobalProperty

	GetNewestUnit(token modules.AssetId) (common.Hash, *modules.ChainIndex, error)
	GetHeaderByNumber(number *modules.ChainIndex) (*modules.Header, error)
	GetAddrUtxos(addr common.Address) (map[modules.OutPoint]*modules.Utxo, error)
	GetAddr1TokenUtxos(addr common.Address, asset *modules.Asset) (map[modules.OutPoint]*modules.Utxo, error)
	GetStableTransactionOnly(hash common.Hash) (*modules.Transaction, error)
	GetStableUnit(hash common.Hash) (*modules.Unit, error)
	GetStableUnitByNumber(number *modules.ChainIndex) (*modules.Unit, error)
}

type IStateQuery added in v1.0.6

type IStateQuery interface {
	GetContractStatesById(contractid []byte) (map[string]*modules.ContractStateValue, error)
	GetContractState(contractid []byte, field string) ([]byte, *modules.StateVersion, error)
	GetContractStatesByPrefix(contractid []byte, prefix string) (map[string]*modules.ContractStateValue, error)
}

type KVRWSet

type KVRWSet struct {
	Reads  map[string]*KVRead  `protobuf:"bytes,1,rep,name=reads" json:"reads,omitempty"`
	Writes map[string]*KVWrite `protobuf:"bytes,3,rep,name=writes" json:"writes,omitempty"`
}

func (*KVRWSet) Descriptor

func (*KVRWSet) Descriptor() ([]byte, []int)

func (*KVRWSet) GetReads

func (m *KVRWSet) GetReads() map[string]*KVRead

func (*KVRWSet) GetWrites

func (m *KVRWSet) GetWrites() map[string]*KVWrite

func (*KVRWSet) MarshalText added in v1.0.6

func (m *KVRWSet) MarshalText() ([]byte, error)

func (*KVRWSet) ProtoMessage

func (*KVRWSet) ProtoMessage()

func (*KVRWSet) Reset

func (m *KVRWSet) Reset()

func (*KVRWSet) String

func (m *KVRWSet) String() string

type KVRead

type KVRead struct {
	ContractId []byte `protobuf:"bytes,4,opt,name=contract_id,proto3" json:"contract_id,omitempty"`
	// contains filtered or unexported fields
}

func NewKVRead

func NewKVRead(contractId []byte, key string, version *modules.StateVersion) *KVRead

NewKVRead helps constructing proto message kvrwset.KVRead

func (*KVRead) Descriptor

func (*KVRead) Descriptor() ([]byte, []int)

func (*KVRead) GetKey

func (m *KVRead) GetKey() string

func (*KVRead) GetValue

func (m *KVRead) GetValue() []byte

func (*KVRead) GetVersion

func (m *KVRead) GetVersion() *modules.StateVersion

func (*KVRead) MarshalText added in v1.0.6

func (m *KVRead) MarshalText() ([]byte, error)

func (*KVRead) ProtoMessage

func (*KVRead) ProtoMessage()

func (*KVRead) Reset

func (m *KVRead) Reset()

func (*KVRead) String

func (m *KVRead) String() string

type KVWrite

type KVWrite struct {
	ContractId []byte `protobuf:"bytes,4,opt,name=contract_id,proto3" json:"contract_id,omitempty"`
	// contains filtered or unexported fields
}

KVWrite captures a write (update/delete) operation performed during transaction simulation

func (*KVWrite) Descriptor

func (*KVWrite) Descriptor() ([]byte, []int)

func (*KVWrite) GetIsDelete

func (m *KVWrite) GetIsDelete() bool

func (*KVWrite) GetKey

func (m *KVWrite) GetKey() string

func (*KVWrite) GetValue

func (m *KVWrite) GetValue() []byte

func (*KVWrite) ProtoMessage

func (*KVWrite) ProtoMessage()

func (*KVWrite) Reset

func (m *KVWrite) Reset()

func (*KVWrite) String

func (m *KVWrite) String() string

type MockIDataQuery added in v1.0.6

type MockIDataQuery struct {
	// contains filtered or unexported fields
}

MockIDataQuery is a mock of IDataQuery interface

func NewMockIDataQuery added in v1.0.6

func NewMockIDataQuery(ctrl *gomock.Controller) *MockIDataQuery

NewMockIDataQuery creates a new mock instance

func (*MockIDataQuery) EXPECT added in v1.0.6

EXPECT returns an object that allows the caller to indicate expected use

func (*MockIDataQuery) GetAddr1TokenUtxos added in v1.0.6

func (m *MockIDataQuery) GetAddr1TokenUtxos(addr common.Address, asset *modules.Asset) (map[modules.OutPoint]*modules.Utxo, error)

GetAddr1TokenUtxos mocks base method

func (*MockIDataQuery) GetAddrUtxos added in v1.0.6

func (m *MockIDataQuery) GetAddrUtxos(addr common.Address) (map[modules.OutPoint]*modules.Utxo, error)

GetAddrUtxos mocks base method

func (*MockIDataQuery) GetContractState added in v1.0.6

func (m *MockIDataQuery) GetContractState(contractid []byte, field string) ([]byte, *modules.StateVersion, error)

GetContractState mocks base method

func (*MockIDataQuery) GetContractStatesById added in v1.0.6

func (m *MockIDataQuery) GetContractStatesById(contractid []byte) (map[string]*modules.ContractStateValue, error)

GetContractStatesById mocks base method

func (*MockIDataQuery) GetContractStatesByPrefix added in v1.0.6

func (m *MockIDataQuery) GetContractStatesByPrefix(contractid []byte, prefix string) (map[string]*modules.ContractStateValue, error)

GetContractStatesByPrefix mocks base method

func (*MockIDataQuery) GetGlobalProp added in v1.0.6

func (m *MockIDataQuery) GetGlobalProp() *modules.GlobalProperty

GetGlobalProp mocks base method

func (*MockIDataQuery) GetHeaderByNumber added in v1.0.6

func (m *MockIDataQuery) GetHeaderByNumber(number *modules.ChainIndex) (*modules.Header, error)

GetHeaderByNumber mocks base method

func (*MockIDataQuery) GetNewestUnit added in v1.0.6

func (m *MockIDataQuery) GetNewestUnit(token modules.AssetId) (common.Hash, *modules.ChainIndex, error)

GetNewestUnit mocks base method

func (*MockIDataQuery) GetStableTransactionOnly added in v1.0.6

func (m *MockIDataQuery) GetStableTransactionOnly(hash common.Hash) (*modules.Transaction, error)

GetStableTransactionOnly mocks base method

func (*MockIDataQuery) GetStableUnit added in v1.0.6

func (m *MockIDataQuery) GetStableUnit(hash common.Hash) (*modules.Unit, error)

GetStableUnit mocks base method

func (*MockIDataQuery) GetStableUnitByNumber added in v1.0.6

func (m *MockIDataQuery) GetStableUnitByNumber(number *modules.ChainIndex) (*modules.Unit, error)

GetStableUnitByNumber mocks base method

func (*MockIDataQuery) UnstableHeadUnitProperty added in v1.0.6

func (m *MockIDataQuery) UnstableHeadUnitProperty(asset modules.AssetId) (*modules.UnitProperty, error)

UnstableHeadUnitProperty mocks base method

type MockIDataQueryMockRecorder added in v1.0.6

type MockIDataQueryMockRecorder struct {
	// contains filtered or unexported fields
}

MockIDataQueryMockRecorder is the mock recorder for MockIDataQuery

func (*MockIDataQueryMockRecorder) GetAddr1TokenUtxos added in v1.0.6

func (mr *MockIDataQueryMockRecorder) GetAddr1TokenUtxos(addr, asset interface{}) *gomock.Call

GetAddr1TokenUtxos indicates an expected call of GetAddr1TokenUtxos

func (*MockIDataQueryMockRecorder) GetAddrUtxos added in v1.0.6

func (mr *MockIDataQueryMockRecorder) GetAddrUtxos(addr interface{}) *gomock.Call

GetAddrUtxos indicates an expected call of GetAddrUtxos

func (*MockIDataQueryMockRecorder) GetContractState added in v1.0.6

func (mr *MockIDataQueryMockRecorder) GetContractState(contractid, field interface{}) *gomock.Call

GetContractState indicates an expected call of GetContractState

func (*MockIDataQueryMockRecorder) GetContractStatesById added in v1.0.6

func (mr *MockIDataQueryMockRecorder) GetContractStatesById(contractid interface{}) *gomock.Call

GetContractStatesById indicates an expected call of GetContractStatesById

func (*MockIDataQueryMockRecorder) GetContractStatesByPrefix added in v1.0.6

func (mr *MockIDataQueryMockRecorder) GetContractStatesByPrefix(contractid, prefix interface{}) *gomock.Call

GetContractStatesByPrefix indicates an expected call of GetContractStatesByPrefix

func (*MockIDataQueryMockRecorder) GetGlobalProp added in v1.0.6

func (mr *MockIDataQueryMockRecorder) GetGlobalProp() *gomock.Call

GetGlobalProp indicates an expected call of GetGlobalProp

func (*MockIDataQueryMockRecorder) GetHeaderByNumber added in v1.0.6

func (mr *MockIDataQueryMockRecorder) GetHeaderByNumber(number interface{}) *gomock.Call

GetHeaderByNumber indicates an expected call of GetHeaderByNumber

func (*MockIDataQueryMockRecorder) GetNewestUnit added in v1.0.6

func (mr *MockIDataQueryMockRecorder) GetNewestUnit(token interface{}) *gomock.Call

GetNewestUnit indicates an expected call of GetNewestUnit

func (*MockIDataQueryMockRecorder) GetStableTransactionOnly added in v1.0.6

func (mr *MockIDataQueryMockRecorder) GetStableTransactionOnly(hash interface{}) *gomock.Call

GetStableTransactionOnly indicates an expected call of GetStableTransactionOnly

func (*MockIDataQueryMockRecorder) GetStableUnit added in v1.0.6

func (mr *MockIDataQueryMockRecorder) GetStableUnit(hash interface{}) *gomock.Call

GetStableUnit indicates an expected call of GetStableUnit

func (*MockIDataQueryMockRecorder) GetStableUnitByNumber added in v1.0.6

func (mr *MockIDataQueryMockRecorder) GetStableUnitByNumber(number interface{}) *gomock.Call

GetStableUnitByNumber indicates an expected call of GetStableUnitByNumber

func (*MockIDataQueryMockRecorder) UnstableHeadUnitProperty added in v1.0.6

func (mr *MockIDataQueryMockRecorder) UnstableHeadUnitProperty(asset interface{}) *gomock.Call

UnstableHeadUnitProperty indicates an expected call of UnstableHeadUnitProperty

type MockIStateQuery added in v1.0.6

type MockIStateQuery struct {
	// contains filtered or unexported fields
}

MockIStateQuery is a mock of IStateQuery interface

func NewMockIStateQuery added in v1.0.6

func NewMockIStateQuery(ctrl *gomock.Controller) *MockIStateQuery

NewMockIStateQuery creates a new mock instance

func (*MockIStateQuery) EXPECT added in v1.0.6

EXPECT returns an object that allows the caller to indicate expected use

func (*MockIStateQuery) GetContractState added in v1.0.6

func (m *MockIStateQuery) GetContractState(contractid []byte, field string) ([]byte, *modules.StateVersion, error)

GetContractState mocks base method

func (*MockIStateQuery) GetContractStatesById added in v1.0.6

func (m *MockIStateQuery) GetContractStatesById(contractid []byte) (map[string]*modules.ContractStateValue, error)

GetContractStatesById mocks base method

func (*MockIStateQuery) GetContractStatesByPrefix added in v1.0.6

func (m *MockIStateQuery) GetContractStatesByPrefix(contractid []byte, prefix string) (map[string]*modules.ContractStateValue, error)

GetContractStatesByPrefix mocks base method

type MockIStateQueryMockRecorder added in v1.0.6

type MockIStateQueryMockRecorder struct {
	// contains filtered or unexported fields
}

MockIStateQueryMockRecorder is the mock recorder for MockIStateQuery

func (*MockIStateQueryMockRecorder) GetContractState added in v1.0.6

func (mr *MockIStateQueryMockRecorder) GetContractState(contractid, field interface{}) *gomock.Call

GetContractState indicates an expected call of GetContractState

func (*MockIStateQueryMockRecorder) GetContractStatesById added in v1.0.6

func (mr *MockIStateQueryMockRecorder) GetContractStatesById(contractid interface{}) *gomock.Call

GetContractStatesById indicates an expected call of GetContractStatesById

func (*MockIStateQueryMockRecorder) GetContractStatesByPrefix added in v1.0.6

func (mr *MockIStateQueryMockRecorder) GetContractStatesByPrefix(contractid, prefix interface{}) *gomock.Call

GetContractStatesByPrefix indicates an expected call of GetContractStatesByPrefix

type RWSetBuilder

type RWSetBuilder struct {
	// contains filtered or unexported fields
}

func NewRWSetBuilder

func NewRWSetBuilder() *RWSetBuilder

func (*RWSetBuilder) AddSupplyToken

func (b *RWSetBuilder) AddSupplyToken(ns string, assetId, uniqueId []byte, amt uint64,
	createAddr common.Address) error

func (*RWSetBuilder) AddToReadSet

func (b *RWSetBuilder) AddToReadSet(contractId []byte, ns string, key string, version *modules.StateVersion)

func (*RWSetBuilder) AddToWriteSet

func (b *RWSetBuilder) AddToWriteSet(contractId []byte, ns string, key string, value []byte)

func (*RWSetBuilder) AddTokenPayOut

func (b *RWSetBuilder) AddTokenPayOut(ns string, address common.Address, asset *modules.Asset, amount uint64, lockTime uint32)

func (*RWSetBuilder) DefineToken

func (b *RWSetBuilder) DefineToken(ns string, tokenType int32, define []byte, createAddr common.Address)

func (*RWSetBuilder) GetTokenDefine

func (b *RWSetBuilder) GetTokenDefine(ns string) *modules.TokenDefine

func (*RWSetBuilder) GetTokenPayOut

func (b *RWSetBuilder) GetTokenPayOut(ns string) []*modules.TokenPayOut

func (*RWSetBuilder) GetTokenSupply

func (b *RWSetBuilder) GetTokenSupply(ns string) []*modules.TokenSupply

func (*RWSetBuilder) GetWriteSet added in v1.0.6

func (b *RWSetBuilder) GetWriteSet(contractId []byte, key string) ([]byte, error)

func (*RWSetBuilder) GetWriteSets added in v1.0.6

func (b *RWSetBuilder) GetWriteSets(contractId []byte) ([]*KVWrite, error)

type RwSetTxMgr

type RwSetTxMgr struct {
	// contains filtered or unexported fields
}

func NewRwSetMgr

func NewRwSetMgr(name string) (*RwSetTxMgr, error)

func (*RwSetTxMgr) Close

func (m *RwSetTxMgr) Close()

func (*RwSetTxMgr) CloseTxSimulator

func (m *RwSetTxMgr) CloseTxSimulator(txId string) error

每次产块结束后,需要关闭该chainId的txsimulator.

func (*RwSetTxMgr) GetTxSimulator added in v1.0.6

func (m *RwSetTxMgr) GetTxSimulator(txId string) (TxSimulator, error)

func (*RwSetTxMgr) NewTxSimulator

func (m *RwSetTxMgr) NewTxSimulator(idag IDataQuery, txId string) (TxSimulator, error)

NewTxSimulator implements method in interface `txmgmt.TxMgr`

type RwSetTxSimulator

type RwSetTxSimulator struct {
	// contains filtered or unexported fields
}

func NewBasedTxSimulator

func NewBasedTxSimulator(txId string, idag IDataQuery, stateQ IStateQuery) *RwSetTxSimulator

func (*RwSetTxSimulator) CheckDone

func (s *RwSetTxSimulator) CheckDone() error

func (*RwSetTxSimulator) Close

func (s *RwSetTxSimulator) Close()

关闭,回收资源,不能再进行读和写

func (*RwSetTxSimulator) DefineToken

func (s *RwSetTxSimulator) DefineToken(ns string, tokenType int32, define []byte, creator string) error

func (*RwSetTxSimulator) DeleteState

func (s *RwSetTxSimulator) DeleteState(contractId []byte, ns string, key string) error

DeleteState implements method in interface `ledger.TxSimulator`

func (*RwSetTxSimulator) Done

func (h *RwSetTxSimulator) Done()

标记为完成,不能再进行PutState等写操作了

func (*RwSetTxSimulator) GetAllStates added in v1.0.6

func (s *RwSetTxSimulator) GetAllStates(contractid []byte, ns string) (map[string]*modules.ContractStateValue, error)

get all dag

func (*RwSetTxSimulator) GetContractState added in v1.0.6

func (s *RwSetTxSimulator) GetContractState(contractid []byte, field string) ([]byte, *modules.StateVersion, error)

func (*RwSetTxSimulator) GetContractStatesById

func (s *RwSetTxSimulator) GetContractStatesById(contractid []byte) (map[string]*modules.ContractStateValue, error)

func (*RwSetTxSimulator) GetContractStatesByPrefix added in v1.0.6

func (s *RwSetTxSimulator) GetContractStatesByPrefix(contractid []byte, prefix string) (map[string]*modules.ContractStateValue, error)

func (*RwSetTxSimulator) GetGlobalProp added in v1.0.2

func (s *RwSetTxSimulator) GetGlobalProp() ([]byte, error)

func (*RwSetTxSimulator) GetPayOutData

func (s *RwSetTxSimulator) GetPayOutData(ns string) ([]*modules.TokenPayOut, error)

func (*RwSetTxSimulator) GetRwData

func (s *RwSetTxSimulator) GetRwData(ns string) ([]*KVRead, []*KVWrite, error)

func (*RwSetTxSimulator) GetStableTransactionByHash added in v1.0.5

func (s *RwSetTxSimulator) GetStableTransactionByHash(ns string, hash common.Hash) (*modules.Transaction, error)

func (*RwSetTxSimulator) GetStableUnit added in v1.0.5

func (s *RwSetTxSimulator) GetStableUnit(ns string, hash common.Hash, unitNumber uint64) (*modules.Unit, error)

func (*RwSetTxSimulator) GetState

func (s *RwSetTxSimulator) GetState(contractid []byte, ns string, key string) ([]byte, error)

GetState implements method in interface `ledger.TxSimulator`

func (*RwSetTxSimulator) GetStatesByPrefix

func (s *RwSetTxSimulator) GetStatesByPrefix(contractid []byte, ns string, prefix string) ([]*modules.KeyValue, error)

func (*RwSetTxSimulator) GetTimestamp

func (s *RwSetTxSimulator) GetTimestamp(ns string, rangeNumber uint32) ([]byte, error)

GetState implements method in interface `ledger.TxSimulator`

func (*RwSetTxSimulator) GetTokenBalance

func (s *RwSetTxSimulator) GetTokenBalance(ns string, addr common.Address, asset *modules.Asset) (
	map[modules.Asset]uint64, error)

func (*RwSetTxSimulator) GetTokenDefineData

func (s *RwSetTxSimulator) GetTokenDefineData(ns string) (*modules.TokenDefine, error)

func (*RwSetTxSimulator) GetTokenSupplyData

func (s *RwSetTxSimulator) GetTokenSupplyData(ns string) ([]*modules.TokenSupply, error)

func (*RwSetTxSimulator) PayOutToken

func (s *RwSetTxSimulator) PayOutToken(ns string, address string, token *modules.Asset, amount uint64,
	lockTime uint32) error

func (*RwSetTxSimulator) Rollback added in v1.0.6

func (s *RwSetTxSimulator) Rollback() error

func (*RwSetTxSimulator) SetState

func (s *RwSetTxSimulator) SetState(contractId []byte, ns string, key string, value []byte) error

func (*RwSetTxSimulator) String

func (s *RwSetTxSimulator) String() string

func (*RwSetTxSimulator) SupplyToken

func (s *RwSetTxSimulator) SupplyToken(ns string, assetId, uniqueId []byte, amt uint64, creator string) error

type TxManager

type TxManager interface {
	Close()
	CloseTxSimulator(txId string) error
	NewTxSimulator(idag IDataQuery, txId string) (TxSimulator, error)
	GetTxSimulator(txId string) (TxSimulator, error)
}
var RwM TxManager

type TxSimulator

type TxSimulator interface {
	IStateQuery
	GetState(contractId []byte, ns string, key string) ([]byte, error)
	GetAllStates(contractId []byte, ns string) (map[string]*modules.ContractStateValue, error)
	GetStatesByPrefix(contractId []byte, ns string, prefix string) ([]*modules.KeyValue, error)
	GetTimestamp(ns string, rangeNumber uint32) ([]byte, error)
	SetState(contractid []byte, ns string, key string, value []byte) error
	GetTokenBalance(ns string, addr common.Address, asset *modules.Asset) (map[modules.Asset]uint64, error)
	GetStableTransactionByHash(ns string, hash common.Hash) (*modules.Transaction, error)
	GetStableUnit(ns string, hash common.Hash, unitNumber uint64) (*modules.Unit, error)
	PayOutToken(ns string, address string, token *modules.Asset, amount uint64, lockTime uint32) error
	DefineToken(ns string, tokenType int32, define []byte, creator string) error
	SupplyToken(ns string, assetId, uniqueId []byte, amt uint64, creator string) error
	DeleteState(contractId []byte, ns string, key string) error

	GetRwData(ns string) ([]*KVRead, []*KVWrite, error)
	GetPayOutData(ns string) ([]*modules.TokenPayOut, error)
	GetTokenDefineData(ns string) (*modules.TokenDefine, error)
	GetTokenSupplyData(ns string) ([]*modules.TokenSupply, error)
	//GetTxSimulationResults() ([]byte, error)
	CheckDone() error
	Done()
	Close()
	Rollback() error
	String() string
	//GetChainParameters() ([]byte, error)
	GetGlobalProp() ([]byte, error)
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL