Documentation ¶
Index ¶
- Constants
- Variables
- func AddNodeAddressesToGenesisAlloc(genesisAlloc core.GenesisAlloc)
- func GenerateRandomString(n int) string
- type DNSSyncingPeerProvider
- type LegacySyncingPeerProvider
- type LocalSyncingPeerProvider
- type Node
- func (node *Node) APIs() []rpc.API
- func (node *Node) AccountManager() *accounts.Manager
- func (node *Node) AddBeaconPeer(p *p2p.Peer) bool
- func (node *Node) AddFaucetContractToPendingTransactions()
- func (node *Node) AddNewBlockForExplorer(block *types.Block)
- func (node *Node) AddPeers(peers []*p2p.Peer) int
- func (node *Node) AddPendingReceipts(receipts *types.CXReceiptsProof)
- func (node *Node) AddPendingStakingTransaction(newStakingTx *staking.StakingTransaction) error
- func (node *Node) AddPendingTransaction(newTx *types.Transaction) error
- func (node *Node) Beaconchain() *core.BlockChain
- func (node *Node) Blockchain() *core.BlockChain
- func (node *Node) BroadcastCXReceipts(newBlock *types.Block, lastCommits []byte)
- func (node *Node) BroadcastCXReceiptsWithShardID(block *types.Block, commitSig []byte, commitBitmap []byte, toShardID uint32)
- func (node *Node) BroadcastCrossLink(newBlock *types.Block)
- func (node *Node) BroadcastMissingCXReceipts()
- func (node *Node) BroadcastNewBlock(newBlock *types.Block)
- func (node *Node) BroadcastSlash(witness *slash.Record)
- func (node *Node) CalculateResponse(request *downloader_pb.DownloaderRequest, incomingPeer string) (*downloader_pb.DownloaderResponse, error)
- func (node *Node) CallFaucetContract(address common.Address) common.Hash
- func (node *Node) ConsensusMessageHandler(msgPayload []byte)
- func (node *Node) DoBeaconSyncing()
- func (node *Node) DoSyncWithoutConsensus()
- func (node *Node) DoSyncing(bc *core.BlockChain, worker *worker.Worker, willJoinConsensus bool)
- func (node *Node) ErroredStakingTransactionSink() []staking.RPCTransactionError
- func (node *Node) ErroredTransactionSink() []types.RPCTransactionError
- func (node *Node) ExplorerMessageHandler(payload []byte)
- func (node *Node) GetBalanceOfAddress(address common.Address) (*big.Int, error)
- func (node *Node) GetHost() p2p.Host
- func (node *Node) GetNonceOfAddress(address common.Address) uint64
- func (node *Node) GetStakingTransactionsHistory(address, txType, order string) ([]common.Hash, error)
- func (node *Node) GetSyncID() [SyncIDLength]byte
- func (node *Node) GetTransactionsHistory(address, txType, order string) ([]common.Hash, error)
- func (node *Node) HandleMessage(content []byte, sender libp2p_peer.ID)
- func (node *Node) InitConsensusWithValidators() (err error)
- func (node *Node) InitSyncingServer()
- func (node *Node) IsCurrentlyLeader() bool
- func (node *Node) IsSameHeight() (uint64, bool)
- func (node *Node) PendingCXReceipts() []*types.CXReceiptsProof
- func (node *Node) PostConsensusProcessing(newBlock *types.Block, commitSigAndBitmap []byte)
- func (node *Node) ProcessCrossLinkMessage(msgPayload []byte)
- func (node *Node) ProcessReceiptMessage(msgPayload []byte)
- func (node *Node) RunServices()
- func (node *Node) SendNewBlockToUnsync()
- func (node *Node) ServiceManager() *service.Manager
- func (node *Node) ServiceManagerSetup()
- func (node *Node) SetBeaconSyncFreq(syncFreq int)
- func (node *Node) SetSyncFreq(syncFreq int)
- func (node *Node) SetupGenesisBlock(db ethdb.Database, shardID uint32, myShardState *shard.State)
- func (node *Node) ShutDown()
- func (node *Node) StartRPC(nodePort string) error
- func (node *Node) StartServer()
- func (node *Node) StartSyncingServer()
- func (node *Node) StopServices()
- func (node *Node) SupportBeaconSyncing()
- func (node *Node) SupportSyncing()
- func (node *Node) VerifyBlockCrossLinks(block *types.Block) error
- func (node *Node) VerifyCrossLink(cl types.CrossLink) error
- func (node *Node) VerifyNewBlock(newBlock *types.Block) error
- func (node *Node) WaitForConsensusReadyV2(readySignal chan struct{}, stopChan chan struct{}, stoppedChan chan struct{})
- type State
- type SyncingPeerProvider
Constants ¶
const ( // NumTryBroadCast is the number of times trying to broadcast NumTryBroadCast = 3 // ClientRxQueueSize is the number of client messages to queue before tail-dropping. ClientRxQueueSize = 16384 // ShardRxQueueSize is the number of shard messages to queue before tail-dropping. ShardRxQueueSize = 16384 // GlobalRxQueueSize is the number of global messages to queue before tail-dropping. GlobalRxQueueSize = 16384 // ClientRxWorkers is the number of concurrent client message handlers. ClientRxWorkers = 8 // ShardRxWorkers is the number of concurrent shard message handlers. ShardRxWorkers = 32 // GlobalRxWorkers is the number of concurrent global message handlers. GlobalRxWorkers = 32 )
const ( // GenesisONEToken is the initial total number of ONE in the genesis block for mainnet. GenesisONEToken = 12600000000 // TestAccountNumber is the number of test accounts for testnet/devnet/ TestAccountNumber = 100 // ContractDeployerInitFund is the initial fund for the contract deployer account in testnet/devnet. ContractDeployerInitFund = 10000000000 // InitFreeFund is the initial fund for permissioned accounts for testnet/devnet/ InitFreeFund = 100 )
const ( SleepPeriod = 20 * time.Millisecond IncomingReceiptsLimit = 6000 // 2000 * (numShards - 1) )
Constants of proposing a new block
const ( SyncFrequency = 60 MinConnectedPeers = 10 // minimum number of peers connected to in node syncing )
Constants related to doing syncing.
const (
FaucetContractFund = 80000000
)
Constants related to smart contract.
const (
//SyncIDLength is the length of bytes for syncID
SyncIDLength = 20
)
Variables ¶
var BigMaxUint64 = new(big.Int).SetBytes([]byte{
255, 255, 255, 255, 255, 255, 255, 255,
})
BigMaxUint64 is maximum possible uint64 value, that is, (1**64)-1.
var ( // GenesisFund is the initial total number of ONE (in Nano) in the genesis block for mainnet. GenesisFund = new(big.Int).Mul(big.NewInt(GenesisONEToken), big.NewInt(denominations.One)) )
Functions ¶
func AddNodeAddressesToGenesisAlloc ¶
func AddNodeAddressesToGenesisAlloc(genesisAlloc core.GenesisAlloc)
AddNodeAddressesToGenesisAlloc adds to the genesis block allocation the accounts used for network validators/nodes, including the account used by the nodes of the initial beacon chain and later new nodes.
func GenerateRandomString ¶
GenerateRandomString generates a random string with given length
Types ¶
type DNSSyncingPeerProvider ¶
type DNSSyncingPeerProvider struct {
// contains filtered or unexported fields
}
DNSSyncingPeerProvider uses the given DNS zone to resolve syncing peers.
func NewDNSSyncingPeerProvider ¶
func NewDNSSyncingPeerProvider(zone, port string) *DNSSyncingPeerProvider
NewDNSSyncingPeerProvider returns a provider that uses given DNS name and port number to resolve syncing peers.
func (*DNSSyncingPeerProvider) SyncingPeers ¶
func (p *DNSSyncingPeerProvider) SyncingPeers(shardID uint32) (peers []p2p.Peer, err error)
SyncingPeers resolves DNS name into peers and returns them.
type LegacySyncingPeerProvider ¶
type LegacySyncingPeerProvider struct {
// contains filtered or unexported fields
}
LegacySyncingPeerProvider uses neighbor lists stored in a Node to serve syncing peer list query.
func NewLegacySyncingPeerProvider ¶
func NewLegacySyncingPeerProvider(node *Node) *LegacySyncingPeerProvider
NewLegacySyncingPeerProvider creates and returns a new node-based syncing peer provider.
func (*LegacySyncingPeerProvider) SyncingPeers ¶
func (p *LegacySyncingPeerProvider) SyncingPeers(shardID uint32) (peers []p2p.Peer, err error)
SyncingPeers returns peers stored in neighbor maps in the node structure.
type LocalSyncingPeerProvider ¶
type LocalSyncingPeerProvider struct {
// contains filtered or unexported fields
}
LocalSyncingPeerProvider uses localnet deployment convention to synthesize syncing peers.
func NewLocalSyncingPeerProvider ¶
func NewLocalSyncingPeerProvider( basePort, selfPort uint16, numShards, shardSize uint32, ) *LocalSyncingPeerProvider
NewLocalSyncingPeerProvider returns a provider that synthesizes syncing peers given the network configuration
func (*LocalSyncingPeerProvider) SyncingPeers ¶
func (p *LocalSyncingPeerProvider) SyncingPeers(shardID uint32) (peers []p2p.Peer, err error)
SyncingPeers returns local syncing peers using the sharding configuration.
type Node ¶
type Node struct { Consensus *consensus.Consensus // Consensus object containing all Consensus related data (e.g. committee members, signatures, commits) BlockChannel chan *types.Block // The channel to send newly proposed blocks ConfirmedBlockChannel chan *types.Block // The channel to send confirmed blocks BeaconBlockChannel chan *types.Block // The channel to send beacon blocks for non-beaconchain nodes DRand *drand.DRand // The instance for distributed randomness protocol Client *client.Client // The presence of a client object means this node will also act as a client SelfPeer p2p.Peer // TODO(minhdoan): it could be duplicated with Self below whose is Alok work. BCPeers []p2p.Peer // list of Beacon Chain Peers. This is needed by all nodes. // TODO: Neighbors should store only neighbor nodes in the same shard Neighbors sync.Map // All the neighbor nodes, key is the sha256 of Peer IP/Port, value is the p2p.Peer State State // State of the Node // BeaconNeighbors store only neighbor nodes in the beacon chain shard BeaconNeighbors sync.Map // All the neighbor nodes, key is the sha256 of Peer IP/Port, value is the p2p.Peer TxPool *core.TxPool CxPool *core.CxPool // pool for missing cross shard receipts resend Worker, BeaconWorker *worker.Worker SyncingPeerProvider SyncingPeerProvider ContractDeployerKey *ecdsa.PrivateKey ContractDeployerCurrentNonce uint64 // The nonce of the deployer contract at current block ContractAddresses []common.Address // node configuration, including group ID, shard ID, etc NodeConfig *nodeconfig.ConfigType // How long in second the leader needs to wait to propose a new block. BlockPeriod time.Duration // contains filtered or unexported fields }
Node represents a protocol-participating node in the network
func New ¶
func New( host p2p.Host, consensusObj *consensus.Consensus, chainDBFactory shardchain.DBFactory, blacklist map[common.Address]struct{}, isArchival bool, ) *Node
New creates a new node.
func (*Node) APIs ¶
APIs return the collection of RPC services the ethereum package offers. NOTE, some of these services probably need to be moved to somewhere else.
func (*Node) AccountManager ¶
AccountManager ...
func (*Node) AddBeaconPeer ¶
AddBeaconPeer adds beacon chain neighbors nodes Return false means new neighbor peer was added Return true means redundant neighbor peer wasn't added
func (*Node) AddFaucetContractToPendingTransactions ¶
func (node *Node) AddFaucetContractToPendingTransactions()
AddFaucetContractToPendingTransactions adds the faucet contract the genesis block.
func (*Node) AddNewBlockForExplorer ¶
AddNewBlockForExplorer add new block for explorer.
func (*Node) AddPendingReceipts ¶
func (node *Node) AddPendingReceipts(receipts *types.CXReceiptsProof)
AddPendingReceipts adds one receipt message to pending list.
func (*Node) AddPendingStakingTransaction ¶
func (node *Node) AddPendingStakingTransaction( newStakingTx *staking.StakingTransaction, ) error
AddPendingStakingTransaction staking transactions
func (*Node) AddPendingTransaction ¶
func (node *Node) AddPendingTransaction(newTx *types.Transaction) error
AddPendingTransaction adds one new transaction to the pending transaction list. This is only called from SDK.
func (*Node) Beaconchain ¶
func (node *Node) Beaconchain() *core.BlockChain
Beaconchain returns the beaconchain from node.
func (*Node) Blockchain ¶
func (node *Node) Blockchain() *core.BlockChain
Blockchain returns the blockchain for the node's current shard.
func (*Node) BroadcastCXReceipts ¶
BroadcastCXReceipts broadcasts cross shard receipts to correspoding destination shards
func (*Node) BroadcastCXReceiptsWithShardID ¶
func (node *Node) BroadcastCXReceiptsWithShardID(block *types.Block, commitSig []byte, commitBitmap []byte, toShardID uint32)
BroadcastCXReceiptsWithShardID broadcasts cross shard receipts to given ToShardID
func (*Node) BroadcastCrossLink ¶ added in v1.3.0
BroadcastCrossLink is called by consensus leader to send the new header as cross link to beacon chain.
func (*Node) BroadcastMissingCXReceipts ¶
func (node *Node) BroadcastMissingCXReceipts()
BroadcastMissingCXReceipts broadcasts missing cross shard receipts per request
func (*Node) BroadcastNewBlock ¶
BroadcastNewBlock is called by consensus leader to sync new blocks with other clients/nodes. NOTE: For now, just send to the client (basically not broadcasting) TODO (lc): broadcast the new blocks to new nodes doing state sync
func (*Node) BroadcastSlash ¶ added in v1.3.0
BroadcastSlash ..
func (*Node) CalculateResponse ¶
func (node *Node) CalculateResponse(request *downloader_pb.DownloaderRequest, incomingPeer string) (*downloader_pb.DownloaderResponse, error)
CalculateResponse implements DownloadInterface on Node object.
func (*Node) CallFaucetContract ¶
CallFaucetContract invokes the faucet contract to give the walletAddress initial money
func (*Node) ConsensusMessageHandler ¶
ConsensusMessageHandler passes received message in node_handler to consensus
func (*Node) DoBeaconSyncing ¶
func (node *Node) DoBeaconSyncing()
DoBeaconSyncing update received beaconchain blocks and downloads missing beacon chain blocks
func (*Node) DoSyncWithoutConsensus ¶
func (node *Node) DoSyncWithoutConsensus()
DoSyncWithoutConsensus gets sync-ed to blockchain without joining consensus
func (*Node) DoSyncing ¶
DoSyncing keep the node in sync with other peers, willJoinConsensus means the node will try to join consensus after catch up
func (*Node) ErroredStakingTransactionSink ¶ added in v1.3.0
func (node *Node) ErroredStakingTransactionSink() []staking.RPCTransactionError
ErroredStakingTransactionSink is the inmemory failed staking transactions this node has
func (*Node) ErroredTransactionSink ¶
func (node *Node) ErroredTransactionSink() []types.RPCTransactionError
ErroredTransactionSink is the inmemory failed transactions this node has
func (*Node) ExplorerMessageHandler ¶
ExplorerMessageHandler passes received message in node_handler to explorer service
func (*Node) GetBalanceOfAddress ¶
GetBalanceOfAddress returns balance of an address.
func (*Node) GetNonceOfAddress ¶
GetNonceOfAddress returns nonce of an address.
func (*Node) GetStakingTransactionsHistory ¶ added in v1.3.7
func (node *Node) GetStakingTransactionsHistory(address, txType, order string) ([]common.Hash, error)
GetStakingTransactionsHistory returns list of staking transactions hashes of address.
func (*Node) GetSyncID ¶
func (node *Node) GetSyncID() [SyncIDLength]byte
GetSyncID returns the syncID of this node
func (*Node) GetTransactionsHistory ¶
GetTransactionsHistory returns list of transactions hashes of address.
func (*Node) HandleMessage ¶
func (node *Node) HandleMessage(content []byte, sender libp2p_peer.ID)
HandleMessage parses the message and dispatch the actions.
func (*Node) InitConsensusWithValidators ¶ added in v1.3.0
InitConsensusWithValidators initialize shard state from latest epoch and update committee pub keys for consensus and drand
func (*Node) InitSyncingServer ¶
func (node *Node) InitSyncingServer()
InitSyncingServer starts downloader server.
func (*Node) IsCurrentlyLeader ¶
IsCurrentlyLeader exposes if node is currently the leader node
func (*Node) IsSameHeight ¶
IsSameHeight tells whether node is at same bc height as a peer
func (*Node) PendingCXReceipts ¶ added in v1.1.1
func (node *Node) PendingCXReceipts() []*types.CXReceiptsProof
PendingCXReceipts returns node.pendingCXReceiptsProof
func (*Node) PostConsensusProcessing ¶
PostConsensusProcessing is called by consensus participants, after consensus is done, to: 1. add the new block to blockchain 2. [leader] send new block to the client 3. [leader] send cross shard tx receipts to destination shard
func (*Node) ProcessCrossLinkMessage ¶ added in v1.3.0
ProcessCrossLinkMessage verify and process Node/CrossLink message into crosslink when it's valid
func (*Node) ProcessReceiptMessage ¶
ProcessReceiptMessage store the receipts and merkle proof in local data store
func (*Node) SendNewBlockToUnsync ¶
func (node *Node) SendNewBlockToUnsync()
SendNewBlockToUnsync send latest verified block to unsync, registered nodes
func (*Node) ServiceManager ¶
ServiceManager ...
func (*Node) ServiceManagerSetup ¶
func (node *Node) ServiceManagerSetup()
ServiceManagerSetup setups service store.
func (*Node) SetBeaconSyncFreq ¶
SetBeaconSyncFreq sets the syncing frequency in the loop
func (*Node) SetSyncFreq ¶
SetSyncFreq sets the syncing frequency in the loop
func (*Node) SetupGenesisBlock ¶
SetupGenesisBlock sets up a genesis blockchain.
func (*Node) ShutDown ¶ added in v1.2.4
func (node *Node) ShutDown()
ShutDown gracefully shut down the node server and dump the in-memory blockchain state into DB.
func (*Node) StartServer ¶
func (node *Node) StartServer()
StartServer starts a server and process the requests by a handler.
func (*Node) StartSyncingServer ¶
func (node *Node) StartSyncingServer()
StartSyncingServer starts syncing server.
func (*Node) SupportBeaconSyncing ¶
func (node *Node) SupportBeaconSyncing()
SupportBeaconSyncing sync with beacon chain for archival node in beacon chan or non-beacon node
func (*Node) SupportSyncing ¶
func (node *Node) SupportSyncing()
SupportSyncing keeps sleeping until it's doing consensus or it's a leader.
func (*Node) VerifyBlockCrossLinks ¶
VerifyBlockCrossLinks verifies the cross links of the block
func (*Node) VerifyCrossLink ¶ added in v1.3.0
VerifyCrossLink verifies the header is valid
func (*Node) VerifyNewBlock ¶
VerifyNewBlock is called by consensus participants to verify the block (account model) they are running consensus on
func (*Node) WaitForConsensusReadyV2 ¶
func (node *Node) WaitForConsensusReadyV2(readySignal chan struct{}, stopChan chan struct{}, stoppedChan chan struct{})
WaitForConsensusReadyV2 listen for the readiness signal from consensus and generate new block for consensus. only leader will receive the ready signal TODO: clean pending transactions for validators; or validators not prepare pending transactions
type State ¶
type State byte
State is a state of a node.
const ( NodeInit State = iota // Node just started, before contacting BeaconChain NodeWaitToJoin // Node contacted BeaconChain, wait to join Shard NodeNotInSync // Node out of sync, might be just joined Shard or offline for a period of time NodeOffline // Node is offline NodeReadyForConsensus // Node is ready for doing consensus NodeDoingConsensus // Node is already doing consensus NodeLeader // Node is the leader of some shard. )
All constants except the NodeLeader below are for validators only.