network

package
v0.0.0-...-602a947 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2018 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
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
)
View Source
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)
)
View Source
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

View Source
const (
	ErrorHandshakeFailed    = 0x01
	ErrorMaxPeersReached    = 0x02
	ErrorUnknownMessageType = 0x03
	ErrorNotImplemented     = 0x04
	ErrorSyncFailed         = 0x05
	ErrorInvalidRequest     = 0x06
	ErrorInvalidResponse    = 0x07
	ErrorNotFound           = 0x08
	ErrorBadBlock           = 0x09
)

protocol errors

View Source
const (
	OpReward   = "REWARD"
	ParamMiner = "MINER"
	ParamUncle = "UNCLE"
	ParamAward = "AWARD"
	MinerAward = "1000000"
	UncleAward = "200000"
	//	RtuDecimal = uint64(4)
	RtuDivisor = uint64(1000000)
)

Variables

View Source
var ProtocolMsgCount = uint64(msgCount)

number of implemented messages for each supported version of the protocol

Functions

func Credit

func Credit(block consensus.Block, account []byte, delta *RTU) error

account is byte array of the hex encoded string for account's bytes

func Debit

func Debit(block consensus.Block, account []byte, delta *RTU) error

account is byte array of the hex encoded string for account's bytes

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 AppConfig

type AppConfig struct {
	// identified application's shard/group on public p2p network
	NetworkId core.Byte16
	// peer's node ID, extracted from p2p connection request
	NodeId []byte
	// name of the node
	NodeName string
	// application's protocol ID
	ProtocolId core.Byte16
}

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

type GetBlockHashesResponseMsg []core.Byte64

response with array of block hashes

type GetBlockHashesRewindMsg

type GetBlockHashesRewindMsg core.Byte64

node needs to rewind back to specified block

type GetBlocksRequestMsg

type GetBlocksRequestMsg []core.Byte64

request block specs for specified hashes

type GetBlocksResponseMsg

type GetBlocksResponseMsg []consensus.BlockSpec

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

type NewBlockMsg consensus.BlockSpec

Announce a new countr block type NewBlockMsg core.BlockSpec

type Op

type Op struct {
	OpCode string            `json:"op_code"       gencodec:"required"`
	Params map[string]string `json:"params"       gencodec:"required"`
}

func NewOp

func NewOp(opCode string) *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

type PeerValidator func(config *AppConfig) error

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

type PowApprover func(hash []byte, blockTs, parentTs uint64) bool

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 BytesToRtu(bytes []byte) *RTU

func MiningRewardBalance

func MiningRewardBalance(block consensus.Block, account []byte) *RTU

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

func Uint64ToRtu(number uint64) *RTU

func (*RTU) Bytes

func (rtu *RTU) Bytes() []byte

func (*RTU) Decimals

func (rtu *RTU) Decimals() uint64

func (*RTU) String

func (rtu *RTU) String() string

func (*RTU) Uint64

func (rtu *RTU) Uint64() uint64

func (*RTU) Units

func (rtu *RTU) Units() uint64

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) Depth

func (s *State) Depth() uint64

func (*State) Get

func (s *State) Get(key []byte) ([]byte, error)

func (*State) GetAllKeys

func (s *State) GetAllKeys() ([][]byte, error)

func (*State) Timestamp

func (s *State) Timestamp() uint64

returns number of nano seconds since Unix epoch

func (*State) Tip

func (s *State) Tip() core.Byte64

func (*State) Weight

func (s *State) Weight() uint64

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 Trustee

type Trustee interface {
	NewMiningRewardTx(block consensus.Block) *consensus.Transaction
	VerifyMiningRewardTx(block consensus.Block) bool
	MiningRewardBalance(block consensus.Block, account []byte) *RTU
}

type TxProcessor

type TxProcessor func(txs *Transaction) bool

a callback provided by application to process submitted transactions for inclusion into a new block

Jump to

Keyboard shortcuts

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