Documentation ¶
Index ¶
- Constants
- Variables
- func InitCurrencyMemberChecker(localRand *rand.Rand, rotateCord bool, rndMemberCount int, ...) consinterface.MemberChecker
- func ValidateTransferTxFormat(tx *TransferTx) error
- type Account
- type AccountStats
- func (as *AccountStats) FailedGenerateTx()
- func (as *AccountStats) FailedValidation()
- func (as *AccountStats) GenerateTx()
- func (as *AccountStats) PassedValidation()
- func (as *AccountStats) Reset()
- func (as AccountStats) StatsString(testDuration time.Duration) string
- func (as AccountStats) String() string
- type AccountTable
- func (at *AccountTable) ConsumeTx(tx *TransferTx, leftOverPub sig.Pub)
- func (at *AccountTable) Copy() *AccountTable
- func (at *AccountTable) DoneClear()
- func (at *AccountTable) DoneKeep()
- func (at *AccountTable) GenerateTx(senders sig.SortPriv, amounts []uint64, recipiants []sig.Pub, ...) (tx *TransferTx, err error)
- func (at *AccountTable) GetAccount(pub sig.Pub) (acc Account, err error)
- func (at *AccountTable) GetAccountInfo(pub sig.Pub) (txCounter, balance uint64, err error)
- func (at *AccountTable) Range(f func(pub sig.PubKeyStr, acc Account) bool)
- func (at *AccountTable) String() string
- func (at *AccountTable) UpdateAccount(pub sig.Pub, account Account)
- func (at *AccountTable) ValidateTx(tx *TransferTx, validateSig bool, leftOverPub sig.Pub) (err error)
- type CurrencyMemberChecker
- func (mc *CurrencyMemberChecker) AddPubKeys(fixedCoord sig.Pub, memberPubKeys, otherPubs sig.PubList, ...)
- func (mc *CurrencyMemberChecker) AllowsChange() bool
- func (mc *CurrencyMemberChecker) New(newIndex types.ConsensusIndex) consinterface.MemberChecker
- func (mc *CurrencyMemberChecker) UpdateState(fixedCoord sig.Pub, prevDec []byte, randBytes [32]byte, ...) (newMemberPubs, newOtherPubs []sig.Pub, changedMembers bool)
- type CurrencyStats
- type InitBlock
- type SimpleCurrencyTxProposer
- func (spi *SimpleCurrencyTxProposer) CheckDecisions(decs [][]byte) (outOforderErrors, errs []error)
- func (spi *SimpleCurrencyTxProposer) DoneClear()
- func (spi *SimpleCurrencyTxProposer) DoneKeep()
- func (spi *SimpleCurrencyTxProposer) EndTest()
- func (spi *SimpleCurrencyTxProposer) GetByzProposal(originProposal []byte, _ *generalconfig.GeneralConfig) (byzProposal []byte)
- func (spi *SimpleCurrencyTxProposer) GetInitialState() []byte
- func (spi *SimpleCurrencyTxProposer) GetProposal()
- func (spi *SimpleCurrencyTxProposer) GetSMStats() consinterface.SMStats
- func (spi *SimpleCurrencyTxProposer) HasDecided(proposer sig.Pub, nxt types.ConsensusInt, dec []byte)
- func (spi *SimpleCurrencyTxProposer) Init(gc *generalconfig.GeneralConfig, lastProposal types.ConsensusInt, ...)
- func (spi *SimpleCurrencyTxProposer) StartIndex(nxt types.ConsensusInt) consinterface.StateMachineInterface
- func (spi *SimpleCurrencyTxProposer) StatsString(testDuration time.Duration) string
- func (spi *SimpleCurrencyTxProposer) SubmitTransaction(tx *TransferTx) error
- func (spi *SimpleCurrencyTxProposer) ValidateProposal(proposer sig.Pub, dec []byte) (err error)
- type TransferTx
- func (tx *TransferTx) Decode(reader io.Reader) (n int, err error)
- func (tx *TransferTx) Encode(writer io.Writer) (n int, err error)
- func (tx *TransferTx) GetConflictObjects() []transactionsm.ConflictObject
- func (tx *TransferTx) GetSignedHash() types.HashBytes
- func (tx *TransferTx) GetSignedMessage() []byte
- type TxBlock
Constants ¶
const MaxParticipants = 100 // TODO
const MaxTxSize = 10000 // TODO
Variables ¶
var ErrIntOverflow = fmt.Errorf("integer overflow")
var ErrInvalidReceiverCount = fmt.Errorf("receivers must match receivers array")
var ErrInvalidSenderCount = fmt.Errorf("senders must match send array")
var ErrInvalidSignatureCount = fmt.Errorf("signature array must match signer array")
var ErrInvalidTxCounter = fmt.Errorf("tx counter does not match account counter")
var ErrInvalidTxCounters = fmt.Errorf("tx counters array much match senders array")
var ErrInvalidTxMerkleRoot = fmt.Errorf("invalid tx Merkle root")
var ErrMustSignFirst = fmt.Errorf("must sign tx before encoding")
var ErrNoSend = fmt.Errorf("must send a at least 1 value")
var ErrNoSender = fmt.Errorf("must have at least one sender")
var ErrNonUniqueReceivers = fmt.Errorf("receivers not unique")
var ErrNonUniqueSenders = fmt.Errorf("senders not unique")
var ErrNotEnoughBalance = fmt.Errorf("account does not have enough balance")
var ErrNotEnoughSend = fmt.Errorf("receive amount exceeds send ammount")
var ErrSendersNotSorted = fmt.Errorf("senders must be sorted")
var ErrSignatureInvalid = fmt.Errorf("signature does not validate")
var ErrTooManyParticipants = fmt.Errorf("too many signatures")
var ErrTooManyTxInBlock = fmt.Errorf("too many transactions in block")
var ErrTxTooLarge = fmt.Errorf("tx too large")
var InitUniqueName = types.GetHash([]byte("should be some unique name"))
Functions ¶
func InitCurrencyMemberChecker ¶
func InitCurrencyMemberChecker(localRand *rand.Rand, rotateCord bool, rndMemberCount int, rndMemberType types.RndMemberType, localRandChangeFrequency types.ConsensusInt, priv sig.Priv, gc *generalconfig.GeneralConfig) consinterface.MemberChecker
func ValidateTransferTxFormat ¶
func ValidateTransferTxFormat(tx *TransferTx) error
ValidateTransferTxFormat returns an error if the decoded transaction format contains any errors.
Types ¶
type Account ¶
func NewAccount ¶
type AccountStats ¶
type AccountStats struct { MoneyTransfered uint64 TxConsumedCount uint64 FailedValidations uint64 PassedValidations uint64 GeneratedTxCount uint64 FailedGenerationTxCount uint64 }
func (*AccountStats) FailedGenerateTx ¶
func (as *AccountStats) FailedGenerateTx()
func (*AccountStats) FailedValidation ¶
func (as *AccountStats) FailedValidation()
func (*AccountStats) GenerateTx ¶
func (as *AccountStats) GenerateTx()
func (*AccountStats) PassedValidation ¶
func (as *AccountStats) PassedValidation()
func (*AccountStats) Reset ¶
func (as *AccountStats) Reset()
func (AccountStats) StatsString ¶
func (as AccountStats) StatsString(testDuration time.Duration) string
func (AccountStats) String ¶
func (as AccountStats) String() string
type AccountTable ¶
type AccountTable struct {
// contains filtered or unexported fields
}
AccountTable provides operations to track a set of accounts. It is not concurrency safe.
func NewAccountTable ¶
func NewAccountTable() *AccountTable
NewAccountTable generates an empty account table.
func (*AccountTable) ConsumeTx ¶
func (at *AccountTable) ConsumeTx(tx *TransferTx, leftOverPub sig.Pub)
ConsumeTx consumes the transaction, sending any leftover sent money to leftOverPub. It should only be called after a transaction has validated correctly.
func (*AccountTable) Copy ¶
func (at *AccountTable) Copy() *AccountTable
func (*AccountTable) DoneClear ¶
func (at *AccountTable) DoneClear()
func (*AccountTable) DoneKeep ¶
func (at *AccountTable) DoneKeep()
func (*AccountTable) GenerateTx ¶
func (at *AccountTable) GenerateTx(senders sig.SortPriv, amounts []uint64, recipiants []sig.Pub, receiveAmounts []uint64) (tx *TransferTx, err error)
GenerateTx generates a transaction given the inputs. An error is returned if the generated transaction would be invalid.
func (*AccountTable) GetAccount ¶
func (at *AccountTable) GetAccount(pub sig.Pub) (acc Account, err error)
GetAccount returns the account object for the given public key.
func (*AccountTable) GetAccountInfo ¶
func (at *AccountTable) GetAccountInfo(pub sig.Pub) (txCounter, balance uint64, err error)
GetAccount info returns the transaction counter and balance of the account.
func (*AccountTable) Range ¶
func (at *AccountTable) Range(f func(pub sig.PubKeyStr, acc Account) bool)
Range performs the func f over the accounts, it stops if f returns false. This should not modify the accounts.
func (*AccountTable) String ¶
func (at *AccountTable) String() string
func (*AccountTable) UpdateAccount ¶
func (at *AccountTable) UpdateAccount(pub sig.Pub, account Account)
func (*AccountTable) ValidateTx ¶
func (at *AccountTable) ValidateTx(tx *TransferTx, validateSig bool, leftOverPub sig.Pub) (err error)
ValidateTx returns an error if the transaction is not valid. If validate sig is false then the transaction's signatures will not be validated. Unspent sent value would be sent to leftOverPub.
type CurrencyMemberChecker ¶
type CurrencyMemberChecker struct {
memberchecker.CustomMemberChecker
}
CurrencyMemberChecker is to be used with SimpleCurrencyTxProposer, it chooses the top memberCount members based on who owns the most currency.
func (*CurrencyMemberChecker) AddPubKeys ¶
func (mc *CurrencyMemberChecker) AddPubKeys(fixedCoord sig.Pub, memberPubKeys, otherPubs sig.PubList, initRandBytes [32]byte, sh *consinterface.Shared)
AddPubKeys adds the pub keys as members to the consensus. Note that for the first consensus we use the pubs directly as given. In following rounds we take the top len(memberPubKeys) with the most currency as the members.
func (*CurrencyMemberChecker) AllowsChange ¶
func (mc *CurrencyMemberChecker) AllowsChange() bool
AllowsChange returns true if the member checker allows changing members, used as a sanity check.
func (*CurrencyMemberChecker) New ¶
func (mc *CurrencyMemberChecker) New(newIndex types.ConsensusIndex) consinterface.MemberChecker
New generates a new member checker for the index, this is called on the inital member checker each time.
func (*CurrencyMemberChecker) UpdateState ¶
func (mc *CurrencyMemberChecker) UpdateState(fixedCoord sig.Pub, prevDec []byte, randBytes [32]byte, prevMember consinterface.MemberChecker, prevSM consinterface.GeneralStateMachineInterface, futureFixed types.ConsensusID) (newMemberPubs, newOtherPubs []sig.Pub, changedMembers bool)
UpdateState chooses the pub keys with the most currency as the next members (keeping the same number of members as the previous member checker)
type CurrencyStats ¶
type CurrencyStats struct { AccStats AccountStats PoolStats transactionsm.PoolStats }
func (CurrencyStats) StatsString ¶
func (cs CurrencyStats) StatsString(testDuration time.Duration) string
type InitBlock ¶
type InitBlock struct { InitPubs []sig.Pub // The initial public keys. InitBalances []uint64 // The initial balances. InitUniqueName types.HashBytes // Should be a unique string. NewPubFunc func() sig.Pub // Used during deserialization, should return an empty public key of the type being used. }
InitBlock represents the initial balances and participants in the currency.
type SimpleCurrencyTxProposer ¶
type SimpleCurrencyTxProposer struct { statemachine.AbsStateMachine statemachine.AbsRandSM // contains filtered or unexported fields }
SimpleCurrencyTxProposer represents the statemachine object for the SimpleCons protocol, only this state machine can be used when testing this object.
func NewSimpleTxProposer ¶
func NewSimpleTxProposer(useRand bool, initRandBytes [32]byte, initBlocksBytes [][]byte, myKeys []sig.Priv, newPubFunc func() sig.Pub, newSigFunc func() sig.Sig) *SimpleCurrencyTxProposer
NewSimpleTxProposer creates an empty SimpleCurrencyTxProposer object.
func (*SimpleCurrencyTxProposer) CheckDecisions ¶
func (spi *SimpleCurrencyTxProposer) CheckDecisions(decs [][]byte) (outOforderErrors, errs []error)
CheckDecisions verifies that the decided values were valid.
func (*SimpleCurrencyTxProposer) DoneClear ¶
func (spi *SimpleCurrencyTxProposer) DoneClear()
DoneClear should be called if the instance of the state machine will no longer be used (it should perform any cleanup).
func (*SimpleCurrencyTxProposer) DoneKeep ¶
func (spi *SimpleCurrencyTxProposer) DoneKeep()
DoneKeep should be called if the instance of the state machine will be kept.
func (*SimpleCurrencyTxProposer) EndTest ¶
func (spi *SimpleCurrencyTxProposer) EndTest()
func (*SimpleCurrencyTxProposer) GetByzProposal ¶
func (spi *SimpleCurrencyTxProposer) GetByzProposal(originProposal []byte, _ *generalconfig.GeneralConfig) (byzProposal []byte)
GetByzProposal should generate a byzantine proposal based on the configuration
func (*SimpleCurrencyTxProposer) GetInitialState ¶
func (spi *SimpleCurrencyTxProposer) GetInitialState() []byte
GetInitialState returns []byte("initial state")
func (*SimpleCurrencyTxProposer) GetProposal ¶
func (spi *SimpleCurrencyTxProposer) GetProposal()
GetProposal is called when a consensus index is ready for a proposal. It should send the proposal for the consensus index by calling mainChannel.HasProposal().
func (*SimpleCurrencyTxProposer) GetSMStats ¶
func (spi *SimpleCurrencyTxProposer) GetSMStats() consinterface.SMStats
GetSMStats returns the statistics object for the SM.
func (*SimpleCurrencyTxProposer) HasDecided ¶
func (spi *SimpleCurrencyTxProposer) HasDecided(proposer sig.Pub, nxt types.ConsensusInt, dec []byte)
HasDecided is called after the index nxt has decided.
func (*SimpleCurrencyTxProposer) Init ¶
func (spi *SimpleCurrencyTxProposer) Init(gc *generalconfig.GeneralConfig, lastProposal types.ConsensusInt, needsConcurrent types.ConsensusInt, mainChannel channelinterface.MainChannel, doneChan chan channelinterface.ChannelCloseType, basicInit bool)
Init initalizes the simple proposal object state.
func (*SimpleCurrencyTxProposer) StartIndex ¶
func (spi *SimpleCurrencyTxProposer) StartIndex(nxt types.ConsensusInt) consinterface.StateMachineInterface
StartIndex is called when a consensus index is ready for a proposal. StartIndex is called when the previous consensus index has finished.
func (*SimpleCurrencyTxProposer) StatsString ¶
func (spi *SimpleCurrencyTxProposer) StatsString(testDuration time.Duration) string
func (*SimpleCurrencyTxProposer) SubmitTransaction ¶
func (spi *SimpleCurrencyTxProposer) SubmitTransaction(tx *TransferTx) error
Submits a transaction to the state machine.
func (*SimpleCurrencyTxProposer) ValidateProposal ¶
func (spi *SimpleCurrencyTxProposer) ValidateProposal(proposer sig.Pub, dec []byte) (err error)
ValidateProposal should return true if the input proposal is valid.
type TransferTx ¶
type TransferTx struct { Senders sig.SortPub // The keys sending the currency. Signatures []sig.Sig // The signatures of the senders (of the serialized transaction). SenderTxCounters []uint64 // The counter of how many transactions each sender has made. Recipiants []sig.Pub // The keys receiving the money. SendAmounts []uint64 // The amount being sent from each sender. ReceiveAmounts []uint64 // The amount being received at each receiver. SignedBytes []byte // The bytes to sign. NewPubFunc func() sig.Pub // Used during deserialzation, should return an empty public key of the type being used. NewSigFunc func() sig.Sig // Used during deserialization, should return an empty signature object of the key type being used. }
TransferTx represents a transaction sending currency from one group of public keys to another.
func (*TransferTx) Decode ¶
func (tx *TransferTx) Decode(reader io.Reader) (n int, err error)
Decode decodes the transaction into tx, returning the number of bytes read and any errors.
func (*TransferTx) Encode ¶
func (tx *TransferTx) Encode(writer io.Writer) (n int, err error)
Encode encodes the transaction into writer, it returns the number of bytes written and any errors.
func (*TransferTx) GetConflictObjects ¶
func (tx *TransferTx) GetConflictObjects() []transactionsm.ConflictObject
GetConflictObjects returns the pub keys.
func (*TransferTx) GetSignedHash ¶
func (tx *TransferTx) GetSignedHash() types.HashBytes
GetSignedHash returns messages.GetHash(tx.GetSignedMessage())
func (*TransferTx) GetSignedMessage ¶
func (tx *TransferTx) GetSignedMessage() []byte
GetSignedBytes returns the bytes that should be signed by the senders.
type TxBlock ¶
type TxBlock struct { Index types.ConsensusInt TxMerkleRoot merkle.MerkleRoot Transactions []*TransferTx PrevHash types.HashBytes NewPubFunc func() sig.Pub NewSigFunc func() sig.Sig }