Documentation ¶
Index ¶
- Constants
- Variables
- func Credit(block consensus.Block, account []byte, delta *RTU) error
- func Debit(block consensus.Block, account []byte, delta *RTU) error
- func NewPeerNode(peer *p2p.Peer, conn p2p.MsgReadWriter) *peerNode
- func NewPlatformManager(appConfig *AppConfig, srvConfig *ServiceConfig, appDb db.Database) (*platformManager, error)
- func NewTrusteeApp(mgr PlatformManager, identity *ecdsa.PrivateKey, appConfig *AppConfig) *trusteeImpl
- type AppConfig
- type GetBlockHashesRequestMsg
- type GetBlockHashesResponseMsg
- type GetBlockHashesRewindMsg
- type GetBlocksRequestMsg
- type GetBlocksResponseMsg
- type HandshakeMsg
- type NewBlockMsg
- type Op
- type PeerNode
- type PeerValidator
- type PlatformConfig
- type PlatformManager
- type PowApprover
- type RTU
- type ServiceConfig
- type State
- type Transaction
- func (tx *Transaction) Block() consensus.Block
- func (tx *Transaction) Delete(key []byte) bool
- func (tx *Transaction) Lookup(key []byte) ([]byte, error)
- func (tx *Transaction) Payload() []byte
- func (tx *Transaction) Signature() []byte
- func (tx *Transaction) Submitter() []byte
- func (tx *Transaction) Update(key, value []byte) bool
- type Trustee
- type TxProcessor
Constants ¶
const ( ERR_NOT_IMPLEMENTED = 0x001 ERR_INITIALIZATION_FAILED = 0x002 ERR_DB_CORRUPTED = 0x003 ERR_INVALID_ARG = 0x100 ERR_TYPE_INCORRECT = 0x400 ERR_REPEAT_BLOCK = 0x409 ERR_DUPLICATE_START = 0x501 ERR_DUPLICATE_SUSPEND = 0x503 ERR_LOW_BALANCE = 0x600 )
const ( // default value will be used for error, since closed channel sends default message CHAN_ERROR = uint8(0) CHAN_NEXT = uint8(1) CHAN_ABORT = uint8(2) CHAN_RETRY = uint8(3) CHAN_DONE = uint8(4) )
const ( // first message between peers Handshake = 0x00 // request to get block hashes during handshake GetBlockHashesRequest = Handshake + 1 // response with block hashes GetBlockHashesResponse = GetBlockHashesRequest + 1 // peer is not on main blockchain and needs to rewind to earlier block GetBlockHashesRewind = GetBlockHashesResponse + 1 // request to get blocks GetBlocksRequest = GetBlockHashesRewind + 1 // response to get blocks GetBlocksResponse = GetBlocksRequest + 1 // new block accouncement NewBlock = GetBlocksResponse + 1 )
protocol messages
const ( ErrorHandshakeFailed = 0x01 ErrorMaxPeersReached = 0x02 ErrorUnknownMessageType = 0x03 ErrorNotImplemented = 0x04 ErrorSyncFailed = 0x05 ErrorInvalidRequest = 0x06 ErrorInvalidResponse = 0x07 ErrorNotFound = 0x08 ErrorBadBlock = 0x09 )
protocol errors
const ( OpReward = "REWARD" ParamMiner = "MINER" ParamUncle = "UNCLE" ParamAward = "AWARD" MinerAward = "1000000" UncleAward = "200000" // RtuDecimal = uint64(4) RtuDivisor = uint64(1000000) )
Variables ¶
var ProtocolMsgCount = uint64(msgCount)
number of implemented messages for each supported version of the protocol
Functions ¶
func NewPeerNode ¶
func NewPeerNode(peer *p2p.Peer, conn p2p.MsgReadWriter) *peerNode
create a new instance of a node based on new peer connection
func NewPlatformManager ¶
func NewPlatformManager(appConfig *AppConfig, srvConfig *ServiceConfig, appDb db.Database) (*platformManager, error)
func NewPlatformManager(config *NetworkConfig, appDb db.Database) (*platformManager, error) {
func NewTrusteeApp ¶
func NewTrusteeApp(mgr PlatformManager, identity *ecdsa.PrivateKey, appConfig *AppConfig) *trusteeImpl
Types ¶
type GetBlockHashesRequestMsg ¶
type GetBlockHashesRequestMsg struct { // starting block's parent's hash ParentHash core.Byte64 `json:"parent_hash" gencodec:"required"` // maximum number of blocks we can handle in response MaxBlocks core.Byte8 `json:"max_blocks" gencodec:"required"` }
request block hashes for descendents of a parent
type GetBlockHashesResponseMsg ¶
response with array of block hashes
type GetBlockHashesRewindMsg ¶
node needs to rewind back to specified block
type GetBlocksRequestMsg ¶
request block specs for specified hashes
type GetBlocksResponseMsg ¶
response with array of requested block specs type GetBlocksResponseMsg []*core.BlockSpec
type HandshakeMsg ¶
type HandshakeMsg struct { // following 3 fields need exact match NetworkId core.Byte16 `json:"network_id" gencodec:"required"` // ShardId core.Byte16 `json:"shard_id" gencodec:"required"` Genesis core.Byte64 `json:"genesis" gencodec:"required"` // application specific protocol compatibility match ProtocolId core.Byte16 `json:"prorocol_id" gencodec:"required"` // // application specific authentication/authorization // AuthToken core.Byte64 `json:"auth_token" gencodec:"required"` // following 2 fields are used for fork resolution TotalWeight core.Byte8 `json:"total_weight" gencodec:"required"` TipNumeric core.Byte8 `json:"tip_numeric" gencodec:"required"` }
the very first message exchanged between two byoi peers upon connection establishment
type NewBlockMsg ¶
Announce a new countr block type NewBlockMsg core.BlockSpec
type Op ¶
type PeerNode ¶
type PeerNode interface { ReadMsg() (p2p.Msg, error) Send(msgcode uint64, data interface{}) error Peer() *p2p.Peer Conn() p2p.MsgReadWriter Status() *HandshakeMsg NodeId() []byte Id() string Name() string SetStatus(status *HandshakeMsg) AddTx(tx interface{}) HasTx(tx interface{}) bool AddBlock(block interface{}) HasBlock(block interface{}) bool }
extracting peer node interface, so can implement mock for testing (see mockNode in test_fixtures.go)
type PeerValidator ¶
a callback provided by application to validate a peer application connection
type PlatformConfig ¶
type PlatformConfig struct { AppConfig ServiceConfig // contains filtered or unexported fields }
type PlatformManager ¶
type PlatformManager interface { // start the platform block producer Start() error // stop the platform processing Stop() error // suspend the platform block producer Suspend() error // query status of a submitted transaction, by its transaction ID // returns the block where it was finalized, or error if not finalized Status(txId *core.Byte64) (consensus.Block, error) // get a snapshot of current world state State() *State // get mining reward balance (nil, for self) MiningRewardBalance(miner []byte) *RTU // get reference to Trustee app for the stack Trustee() Trustee // submit a transaction payload, and get a transaction ID Submit(txPayload, signature, submitter []byte) *core.Byte64 // get a list of current peers Peers() []AppConfig // disconnect a specific peer Disconnect(app *AppConfig) error }
type PowApprover ¶
a callback provided by application to approve PoW (arguments include block's timestamp and delta time since parent block, so that application can implement variable PoW schemes based on time when block was generated and time since its parent)
type RTU ¶
type RTU uint64
func BytesToRtu ¶
func MiningRewardBalance ¶
get account's reward balance based on world view of the block account is byte array of the hex encoded string for account's bytes
func Uint64ToRtu ¶
type ServiceConfig ¶
type ServiceConfig struct { // application's identity ECDSA key // (required) IdentityKey *ecdsa.PrivateKey // port for application to listen Port string // NAT traversal preference Nat bool // appication's protocol name ProtocolName string // appication's protocol version ProtocolVersion uint // list of bootstrap nodes BootstrapNodes []string // application callback to process transactions // (required) TxProcessor TxProcessor // application callback to approve PoW condition // (optional: set to nil, if no PoW required) PowApprover PowApprover // application callback to validate peer application // (required) PeerValidator PeerValidator }
type State ¶
type State struct {
// contains filtered or unexported fields
}
container to access world state information
func (*State) GetAllKeys ¶
type Transaction ¶
type Transaction struct { // payload []byte consensus.Transaction // contains filtered or unexported fields }
func (*Transaction) Block ¶
func (tx *Transaction) Block() consensus.Block
get reference to transaction's block, for use with trustee methods
func (*Transaction) Delete ¶
func (tx *Transaction) Delete(key []byte) bool
delete a key in current world state view
func (*Transaction) Lookup ¶
func (tx *Transaction) Lookup(key []byte) ([]byte, error)
lookup a key in current world state view
func (*Transaction) Payload ¶
func (tx *Transaction) Payload() []byte
provide application submitted transaction payload
func (*Transaction) Signature ¶
func (tx *Transaction) Signature() []byte
provide signature of the payload
func (*Transaction) Submitter ¶
func (tx *Transaction) Submitter() []byte
provide submitter's public key
func (*Transaction) Update ¶
func (tx *Transaction) Update(key, value []byte) bool
update a key in current world state view
type TxProcessor ¶
type TxProcessor func(txs *Transaction) bool
a callback provided by application to process submitted transactions for inclusion into a new block