Add receipt local storage and pending list

pull/1357/head
Rongjian Lan 5 years ago
parent 2a8882eb90
commit 5580d0df15
  1. 2
      api/client/client.go
  2. 8
      cmd/harmony/main.go
  3. 2
      consensus/consensus_service.go
  4. 48
      core/blockchain.go
  5. 25
      core/rawdb/accessors_chain.go
  6. 25
      core/rawdb/schema.go
  7. 2
      core/types/block.go
  8. 2
      core/types/crosslink.go
  9. 10
      core/types/cx_receipt.go
  10. 2
      core/types/transaction.go
  11. 4
      internal/configs/node/config.go
  12. 17
      node/node.go
  13. 51
      node/node_cross_shard.go
  14. 4
      node/node_genesis.go
  15. 14
      node/node_handler.go
  16. 2
      p2p/group.go

@ -7,7 +7,7 @@ import (
// Client represents a node (e.g. a wallet) which sends transactions and receives responses from the harmony network
type Client struct {
ShardID uint32 // ShardID
ShardID uint32 // ShardIDs
UpdateBlocks func([]*types.Block) // Closure function used to sync new block with the leader. Once the leader finishes the consensus on a new block, it will send it to the clients. Clients use this method to update their blockchain
// The p2p host used to send/receive p2p messages

@ -327,7 +327,7 @@ func setupConsensusAndNode(nodeConfig *nodeconfig.ConfigType) *node.Node {
// TODO: Disable drand. Currently drand isn't functioning but we want to compeletely turn it off for full protection.
// Enable it back after mainnet.
// dRand := drand.New(nodeConfig.Host, nodeConfig.ShardID, []p2p.Peer{}, nodeConfig.Leader, currentNode.ConfirmedBlockChannel, nodeConfig.ConsensusPriKey)
// dRand := drand.New(nodeConfig.Host, nodeConfig.ShardIDs, []p2p.Peer{}, nodeConfig.Leader, currentNode.ConfirmedBlockChannel, nodeConfig.ConsensusPriKey)
// currentNode.Consensus.RegisterPRndChannel(dRand.PRndChannel)
// currentNode.Consensus.RegisterRndChannel(dRand.RndChannel)
// currentNode.DRand = dRand
@ -398,14 +398,14 @@ func main() {
}
if *shardID >= 0 {
utils.GetLogInstance().Info("ShardID Override", "original", initialAccount.ShardID, "override", *shardID)
utils.GetLogInstance().Info("ShardIDs Override", "original", initialAccount.ShardID, "override", *shardID)
initialAccount.ShardID = uint32(*shardID)
}
nodeConfig := createGlobalConfig()
currentNode := setupConsensusAndNode(nodeConfig)
//if consensus.ShardID != 0 {
//if consensus.ShardIDs != 0 {
// go currentNode.SupportBeaconSyncing()
//}
@ -415,7 +415,7 @@ func main() {
}
utils.GetLogInstance().Info(startMsg,
"BlsPubKey", hex.EncodeToString(nodeConfig.ConsensusPubKey.Serialize()),
"ShardID", nodeConfig.ShardID,
"ShardIDs", nodeConfig.ShardID,
"ShardGroupID", nodeConfig.GetShardGroupID(),
"BeaconGroupID", nodeConfig.GetBeaconGroupID(),
"ClientGroupID", nodeConfig.GetClientGroupID(),

@ -403,7 +403,7 @@ func (consensus *Consensus) String() string {
} else {
duty = "VLD" // validator
}
return fmt.Sprintf("[duty:%s, PubKey:%s, ShardID:%v]",
return fmt.Sprintf("[duty:%s, PubKey:%s, ShardIDs:%v]",
duty, consensus.PubKey.SerializeToHexStr(), consensus.ShardID)
}

@ -405,7 +405,7 @@ func (bc *BlockChain) FastSyncCommitHead(hash common.Hash) error {
return nil
}
// ShardID returns the shard Id of the blockchain.
// ShardIDs returns the shard Id of the blockchain.
func (bc *BlockChain) ShardID() uint32 {
return uint32(bc.chainConfig.ChainID.Int64())
}
@ -1061,7 +1061,7 @@ func (bc *BlockChain) WriteBlockWithState(block *types.Block, receipts []*types.
continue
}
shardReceipts := GetToShardReceipts(cxReceipts, uint32(i))
rawdb.WriteCXReceipts(batch, uint32(i), block.NumberU64(), block.Hash(), shardReceipts)
rawdb.WriteCXReceipts(batch, uint32(i), block.NumberU64(), block.Hash(), shardReceipts, false)
}
// If the total difficulty is higher than our known, add it to the canonical chain
@ -2008,7 +2008,6 @@ func (bc *BlockChain) ReadCrossLink(shardID uint32, blockNum uint64, temp bool)
}
// WriteShardLastCrossLink saves the last crosslink of a shard
// temp=true is to write the just received cross link that's not committed into blockchain with consensus
func (bc *BlockChain) WriteShardLastCrossLink(shardID uint32, cl types.CrossLink) error {
return rawdb.WriteShardLastCrossLink(bc.db, cl.ShardID(), cl.Serialize())
}
@ -2024,17 +2023,6 @@ func (bc *BlockChain) ReadShardLastCrossLink(shardID uint32) (*types.CrossLink,
return crossLink, err
}
// ReadLastShardCrossLink retrieves last crosslink of a shard.
func (bc *BlockChain) ReadLastShardCrossLink(shardID uint32, blockNum uint64, temp bool) (*types.CrossLink, error) {
bytes, err := rawdb.ReadCrossLinkShardBlock(bc.db, shardID, blockNum, temp)
if err != nil {
return nil, err
}
crossLink, err := types.DeserializeCrossLink(bytes)
return crossLink, err
}
// IsSameLeaderAsPreviousBlock retrieves a block from the database by number, caching it
func (bc *BlockChain) IsSameLeaderAsPreviousBlock(block *types.Block) bool {
if block.NumberU64() == 0 {
@ -2069,19 +2057,33 @@ func GetToShardReceipts(cxReceipts types.CXReceipts, shardID uint32) types.CXRec
return cxs
}
// CXReceipts retrieves the cross shard transaction receipts of a given shard
func (bc *BlockChain) CXReceipts(shardID uint32, blockNum uint64, blockHash common.Hash) (types.CXReceipts, error) {
cxs, err := rawdb.ReadCXReceipts(bc.db, shardID, blockNum, blockHash)
// ReadCXReceipts retrieves the cross shard transaction receipts of a given shard
// temp=true is to retrieve the just received receipts that's not committed into blockchain with consensus
func (bc *BlockChain) ReadCXReceipts(shardID uint32, blockNum uint64, blockHash common.Hash, temp bool) (types.CXReceipts, error) {
cxs, err := rawdb.ReadCXReceipts(bc.db, shardID, blockNum, blockHash, temp)
if err != nil || len(cxs) == 0 {
return nil, err
}
return cxs, nil
}
// WriteCXReceipts saves the cross shard transaction receipts of a given shard
// temp=true is to store the just received receipts that's not committed into blockchain with consensus
func (bc *BlockChain) WritePendingCXReceipts(shardID uint32, blockNum uint64, blockHash common.Hash, receipts types.CXReceipts, temp bool) error {
return rawdb.WriteCXReceipts(bc.db, shardID, blockNum, blockHash, receipts, temp)
}
// WriteCXReceipts saves the cross shard transaction receipts of a given shard
// temp=true is to store the just received receipts that's not committed into blockchain with consensus
func (bc *BlockChain) WriteCXReceipts(shardID uint32, blockNum uint64, blockHash common.Hash, receipts types.CXReceipts, temp bool) error {
return rawdb.WriteCXReceipts(bc.db, shardID, blockNum, blockHash, receipts, temp)
}
// CXMerkleProof calculates the cross shard transaction merkle proof of a given destination shard
func (bc *BlockChain) CXMerkleProof(shardID uint32, block *types.Block) (*types.CXMerkleProof, error) {
proof := &types.CXMerkleProof{BlockHash: block.Hash(), CXReceiptHash: block.Header().OutgoingReceiptHash, CXShardHash: []common.Hash{}, ShardID: []uint32{}}
cxs, err := rawdb.ReadCXReceipts(bc.db, shardID, block.NumberU64(), block.Hash())
proof := &types.CXMerkleProof{BlockNum: block.Number(), BlockHash: block.Hash(), ShardID: block.ShardID(), CXReceiptHash: block.Header().OutgoingReceiptHash, CXShardHashes: []common.Hash{}, ShardIDs: []uint32{}}
cxs, err := rawdb.ReadCXReceipts(bc.db, shardID, block.NumberU64(), block.Hash(), false)
if err != nil || cxs == nil {
return nil, err
}
@ -2091,16 +2093,16 @@ func (bc *BlockChain) CXMerkleProof(shardID uint32, block *types.Block) (*types.
shardNum := int(shardingConfig.NumShards())
for i := 0; i < shardNum; i++ {
receipts, err := bc.CXReceipts(uint32(i), block.NumberU64(), block.Hash())
receipts, err := bc.ReadCXReceipts(uint32(i), block.NumberU64(), block.Hash(), false)
if err != nil || len(receipts) == 0 {
continue
} else {
hash := types.DeriveSha(receipts)
proof.CXShardHash = append(proof.CXShardHash, hash)
proof.ShardID = append(proof.ShardID, uint32(i))
proof.CXShardHashes = append(proof.CXShardHashes, hash)
proof.ShardIDs = append(proof.ShardIDs, uint32(i))
}
}
if len(proof.ShardID) == 0 {
if len(proof.ShardIDs) == 0 {
return nil, nil
}
return proof, nil

@ -504,20 +504,12 @@ func WriteEpochVdfBlockNum(db DatabaseWriter, epoch *big.Int, data []byte) error
// ReadCrossLinkShardBlock retrieves the blockHash given shardID and blockNum
func ReadCrossLinkShardBlock(db DatabaseReader, shardID uint32, blockNum uint64, temp bool) ([]byte, error) {
if temp {
// cross link received but haven't committed into blockchain with consensus
return db.Get(tempCrosslinkKey(shardID, blockNum))
}
return db.Get(crosslinkKey(shardID, blockNum))
return db.Get(crosslinkKey(shardID, blockNum, temp))
}
// WriteCrossLinkShardBlock stores the blockHash given shardID and blockNum
func WriteCrossLinkShardBlock(db DatabaseWriter, shardID uint32, blockNum uint64, data []byte, temp bool) error {
if temp {
// cross link received but haven't committed into blockchain with consensus
return db.Put(tempCrosslinkKey(shardID, blockNum), data)
}
return db.Put(crosslinkKey(shardID, blockNum), data)
return db.Put(crosslinkKey(shardID, blockNum, temp), data)
}
// ReadShardLastCrossLink read the last cross link of a shard
@ -531,8 +523,8 @@ func WriteShardLastCrossLink(db DatabaseWriter, shardID uint32, data []byte) err
}
// ReadCXReceipts retrieves all the transactions of receipts given destination shardID, number and blockHash
func ReadCXReceipts(db DatabaseReader, shardID uint32, number uint64, hash common.Hash) (types.CXReceipts, error) {
data, err := db.Get(cxReceiptKey(shardID, number, hash))
func ReadCXReceipts(db DatabaseReader, shardID uint32, number uint64, hash common.Hash, temp bool) (types.CXReceipts, error) {
data, err := db.Get(cxReceiptKey(shardID, number, hash, temp))
if len(data) == 0 || err != nil {
utils.Logger().Info().Err(err).Uint64("number", number).Int("dataLen", len(data)).Msg("ReadCXReceipts")
return nil, err
@ -546,20 +538,21 @@ func ReadCXReceipts(db DatabaseReader, shardID uint32, number uint64, hash commo
}
// WriteCXReceipts stores all the transaction receipts given destination shardID, blockNumber and blockHash
func WriteCXReceipts(db DatabaseWriter, shardID uint32, number uint64, hash common.Hash, receipts types.CXReceipts) {
func WriteCXReceipts(db DatabaseWriter, shardID uint32, number uint64, hash common.Hash, receipts types.CXReceipts, temp bool) error {
bytes, err := rlp.EncodeToBytes(receipts)
if err != nil {
utils.Logger().Error().Msg("[WriteCXReceipts] Failed to encode cross shard tx receipts")
}
// Store the receipt slice
if err := db.Put(cxReceiptKey(shardID, number, hash), bytes); err != nil {
if err := db.Put(cxReceiptKey(shardID, number, hash, temp), bytes); err != nil {
utils.Logger().Error().Msg("[WriteCXReceipts] Failed to store cxreceipts")
}
return err
}
// DeleteCXReceipts removes all receipt data associated with a block hash.
func DeleteCXReceipts(db DatabaseDeleter, shardID uint32, number uint64, hash common.Hash) {
if err := db.Delete(cxReceiptKey(shardID, number, hash)); err != nil {
func DeleteCXReceipts(db DatabaseDeleter, shardID uint32, number uint64, hash common.Hash, temp bool) {
if err := db.Delete(cxReceiptKey(shardID, number, hash, temp)); err != nil {
utils.Logger().Error().Msg("Failed to delete cross shard tx receipts")
}
}

@ -65,6 +65,7 @@ var (
tempCrosslinkPrefix = []byte("tempCrosslink") // prefix for tempCrosslink
cxReceiptPrefix = []byte("cxReceipt") // prefix for cross shard transaction receipt
tempCxReceiptPrefix = []byte("tempCxReceipt") // prefix for temporary cross shard transaction receipt
cxReceiptHashPrefix = []byte("cxReceiptHash") // prefix for cross shard transaction receipt hash
// epochBlockNumberPrefix + epoch (big.Int.Bytes())
@ -177,27 +178,27 @@ func shardLastCrosslinkKey(shardID uint32) []byte {
return key
}
func crosslinkKey(shardID uint32, blockNum uint64) []byte {
func crosslinkKey(shardID uint32, blockNum uint64, temp bool) []byte {
prefix := crosslinkPrefix
if temp {
prefix = tempCrosslinkPrefix
}
sbKey := make([]byte, 12)
binary.BigEndian.PutUint32(sbKey, shardID)
binary.BigEndian.PutUint64(sbKey[4:], blockNum)
key := append(crosslinkPrefix, sbKey...)
return key
}
func tempCrosslinkKey(shardID uint32, blockNum uint64) []byte {
sbKey := make([]byte, 12)
binary.BigEndian.PutUint32(sbKey, shardID)
binary.BigEndian.PutUint64(sbKey[4:], blockNum)
key := append(tempCrosslinkPrefix, sbKey...)
key := append(prefix, sbKey...)
return key
}
// cxReceiptKey = cxReceiptsPrefix + shardID + num (uint64 big endian) + hash
func cxReceiptKey(shardID uint32, number uint64, hash common.Hash) []byte {
func cxReceiptKey(shardID uint32, number uint64, hash common.Hash, temp bool) []byte {
prefix := cxReceiptPrefix
if temp {
prefix = tempCxReceiptPrefix
}
sKey := make([]byte, 4)
binary.BigEndian.PutUint32(sKey, shardID)
tmp := append(cxReceiptPrefix, sKey...)
tmp := append(prefix, sKey...)
tmp1 := append(tmp, encodeBlockNumber(number)...)
return append(tmp1, hash.Bytes()...)
}

@ -368,7 +368,7 @@ func (b *Block) NumberU64() uint64 { return b.header.Number.Uint64() }
// MixDigest is the header mix digest.
func (b *Block) MixDigest() common.Hash { return b.header.MixDigest }
// ShardID is the header ShardID
// ShardIDs is the header ShardIDs
func (b *Block) ShardID() uint32 { return b.header.ShardID }
// Bloom returns header bloom.

@ -24,7 +24,7 @@ func (cl CrossLink) Header() *Header {
return cl.ChainHeader
}
// ShardID returns shardID
// ShardIDs returns shardID
func (cl CrossLink) ShardID() uint32 {
return cl.ChainHeader.ShardID
}

@ -18,7 +18,7 @@ type CXReceipt struct {
Amount *big.Int
}
// CXReceipts is a list of CXReceipt
// ReadCXReceipts is a list of CXReceipt
type CXReceipts []*CXReceipt
// Len returns the length of s.
@ -65,8 +65,10 @@ func NewCrossShardReceipt(txHash common.Hash, nonce uint64, from common.Address,
// CXMerkleProof represents the merkle proof of a collection of ordered cross shard transactions
type CXMerkleProof struct {
BlockHash common.Hash // block header's hash
BlockNum *big.Int // block header's hash
BlockHash common.Hash // block header's Hash
ShardID uint32 // block header's shardID
CXReceiptHash common.Hash // root hash of the cross shard receipts in a given block
ShardID []uint32 // order list, records destination shardID
CXShardHash []common.Hash // ordered hash list, each hash corresponds to one destination shard's receipts root hash
ShardIDs []uint32 // order list, records destination shardID
CXShardHashes []common.Hash // ordered hash list, each hash corresponds to one destination shard's receipts root hash
}

@ -172,7 +172,7 @@ func (tx *Transaction) ChainID() *big.Int {
return deriveChainID(tx.data.V)
}
// ShardID returns which shard id this transaction was signed for (if at all)
// ShardIDs returns which shard id this transaction was signed for (if at all)
func (tx *Transaction) ShardID() uint32 {
return tx.data.ShardID
}

@ -73,7 +73,7 @@ type ConfigType struct {
client p2p.GroupID // the client group ID of the shard
isClient bool // whether this node is a client node, such as wallet/txgen
isBeacon bool // whether this node is beacon node doing consensus or not
ShardID uint32 // ShardID of this node
ShardID uint32 // ShardIDs of this node
role Role // Role of the node
Port string // Port of the node.
IP string // IP of the node.
@ -156,7 +156,7 @@ func (conf *ConfigType) SetIsClient(b bool) {
conf.isClient = b
}
// SetShardID set the ShardID
// SetShardID set the ShardIDs
func (conf *ConfigType) SetShardID(s uint32) {
conf.ShardID = s
}

@ -6,6 +6,8 @@ import (
"sync"
"time"
"github.com/harmony-one/harmony/api/proto/node"
"github.com/ethereum/go-ethereum/common"
"github.com/harmony-one/harmony/accounts"
"github.com/harmony-one/harmony/api/client"
@ -92,6 +94,9 @@ type Node struct {
pendingCrossLinks []*types.Header
pendingClMutex sync.Mutex
pendingCXReceipts []*node.CXReceiptsMessage // All the receipts received but not yet processed for Consensus
pendingCXMutex sync.Mutex
// Shard databases
shardChains shardchain.Collection
@ -250,6 +255,16 @@ func (node *Node) AddPendingTransaction(newTx *types.Transaction) {
}
}
// AddPendingReceipts adds one receipt message to pending list.
func (node *Node) AddPendingReceipts(receipts *node.CXReceiptsMessage) {
if node.NodeConfig.GetNetworkType() != nodeconfig.Mainnet {
node.pendingCXMutex.Lock()
node.pendingCXReceipts = append(node.pendingCXReceipts, receipts)
node.pendingCXMutex.Unlock()
utils.Logger().Error().Int("totalPendingReceipts", len(node.pendingCXReceipts)).Msg("Got ONE more receipt message")
}
}
// Take out a subset of valid transactions from the pending transaction list
// Note the pending transaction list will then contain the rest of the txs
func (node *Node) getTransactionsForNewBlock(maxNumTxs int, coinbase common.Address) types.Transactions {
@ -349,7 +364,7 @@ func New(host p2p.Host, consensusObj *consensus.Consensus, chainDBFactory shardc
node.AddContractKeyAndAddress(scFaucet)
}
//if node.Consensus.ShardID == 0 {
//if node.Consensus.ShardIDs == 0 {
// // Contracts only exist in beacon chain
// if node.isFirstTime {
// // Setup one time smart contracts

@ -4,7 +4,6 @@ import (
"encoding/binary"
"bytes"
"encoding/base64"
"github.com/harmony-one/bls/ffi/go/bls"
@ -13,7 +12,6 @@ import (
"github.com/ethereum/go-ethereum/rlp"
proto_node "github.com/harmony-one/harmony/api/proto/node"
"github.com/harmony-one/harmony/core"
"github.com/harmony-one/harmony/core/types"
bls_cosi "github.com/harmony-one/harmony/crypto/bls"
"github.com/harmony-one/harmony/internal/ctxerror"
@ -156,19 +154,20 @@ func (node *Node) ProcessReceiptMessage(msgPayload []byte) {
var foundMyShard bool
byteBuffer := bytes.NewBuffer([]byte{})
if len(merkleProof.ShardID) == 0 {
if len(merkleProof.ShardIDs) == 0 {
utils.Logger().Warn().Msg("[ProcessReceiptMessage] There is No non-empty destination shards")
return
}
for j := 0; j < len(merkleProof.ShardID); j++ {
// Find receipts with my shard as destination
for j := 0; j < len(merkleProof.ShardIDs); j++ {
sKey := make([]byte, 4)
binary.BigEndian.PutUint32(sKey, merkleProof.ShardID[j])
binary.BigEndian.PutUint32(sKey, merkleProof.ShardIDs[j])
byteBuffer.Write(sKey)
byteBuffer.Write(merkleProof.CXShardHash[j][:])
if merkleProof.ShardID[j] == node.Consensus.ShardID {
byteBuffer.Write(merkleProof.CXShardHashes[j][:])
if merkleProof.ShardIDs[j] == node.Consensus.ShardID {
foundMyShard = true
myShardRoot = merkleProof.CXShardHash[j]
myShardRoot = merkleProof.CXShardHashes[j]
}
}
@ -177,30 +176,30 @@ func (node *Node) ProcessReceiptMessage(msgPayload []byte) {
return
}
hash := crypto.Keccak256Hash(byteBuffer.Bytes())
utils.Logger().Debug().Interface("hash", hash).Msg("[ProcessReceiptMessage] RootHash of the CXReceipts")
// TODO chao: use crosslink from beacon sync to verify the hash
cxReceipts := cxmsg.Receipts
sha := types.DeriveSha(cxReceipts)
// Check whether the receipts matches the receipt merkle root
receiptsForMyShard := cxmsg.Receipts
sha := types.DeriveSha(receiptsForMyShard)
if sha != myShardRoot {
utils.Logger().Warn().Interface("calculated", sha).Interface("got", myShardRoot).Msg("[ProcessReceiptMessage] Trie Root of CXReceipts Not Match")
utils.Logger().Warn().Interface("calculated", sha).Interface("got", myShardRoot).Msg("[ProcessReceiptMessage] Trie Root of ReadCXReceipts Not Match")
return
}
txs := types.Transactions{}
inputData, _ := base64.StdEncoding.DecodeString("")
gas, err := core.IntrinsicGas(inputData, false, true)
if err != nil {
utils.Logger().Warn().Err(err).Msg("cannot calculate required gas")
if len(receiptsForMyShard) == 0 {
return
}
for _, cx := range cxReceipts {
// TODO chao: add gas fee to incentivize
tx := types.NewCrossShardTransaction(0, cx.To, cx.ShardID, cx.ToShardID, cx.Amount, gas, nil, inputData)
txs = append(txs, tx)
}
node.addPendingTransactions(txs)
sourceShardID := merkleProof.ShardID
sourceBlockNum := merkleProof.BlockNum
sourceBlockHash := merkleProof.BlockHash
// TODO: check message signature is from the nodes of source shard.
node.Blockchain().WriteCXReceipts(sourceShardID, sourceBlockNum.Uint64(), sourceBlockHash, receiptsForMyShard, true)
// Check merkle proof with crosslink of the source shard
hash := crypto.Keccak256Hash(byteBuffer.Bytes())
utils.Logger().Debug().Interface("hash", hash).Msg("[ProcessReceiptMessage] RootHash of the CXReceipts")
// TODO chao: use crosslink from beacon sync to verify the hash
node.AddPendingReceipts(&cxmsg)
}
// ProcessCrossShardTx verify and process cross shard transaction on destination shard

@ -93,8 +93,8 @@ func (node *Node) SetupGenesisBlock(db ethdb.Database, shardID uint32, myShardSt
}
// Initialize shard state
// TODO: add ShardID into chainconfig and change ChainID to NetworkID
chainConfig.ChainID = big.NewInt(int64(shardID)) // Use ChainID as piggybacked ShardID
// TODO: add ShardIDs into chainconfig and change ChainID to NetworkID
chainConfig.ChainID = big.NewInt(int64(shardID)) // Use ChainID as piggybacked ShardIDs
gspec := core.Genesis{
Config: &chainConfig,

@ -318,9 +318,9 @@ func (node *Node) BroadcastCXReceipts(newBlock *types.Block) {
if i == int(myShardID) {
continue
}
cxReceipts, err := node.Blockchain().CXReceipts(uint32(i), newBlock.NumberU64(), newBlock.Hash())
cxReceipts, err := node.Blockchain().ReadCXReceipts(uint32(i), newBlock.NumberU64(), newBlock.Hash(), false)
if err != nil || len(cxReceipts) == 0 {
//utils.Logger().Warn().Err(err).Uint32("ToShardID", uint32(i)).Int("numCXReceipts", len(cxReceipts)).Msg("[BroadcastCXReceipts] No CXReceipts found")
//utils.Logger().Warn().Err(err).Uint32("ToShardID", uint32(i)).Int("numCXReceipts", len(cxReceipts)).Msg("[BroadcastCXReceipts] No ReadCXReceipts found")
continue
}
merkleProof, err := node.Blockchain().CXMerkleProof(uint32(i), newBlock)
@ -328,7 +328,7 @@ func (node *Node) BroadcastCXReceipts(newBlock *types.Block) {
utils.Logger().Warn().Uint32("ToShardID", uint32(i)).Msg("[BroadcastCXReceipts] Unable to get merkleProof")
continue
}
utils.Logger().Info().Uint32("ToShardID", uint32(i)).Msg("[BroadcastCXReceipts] CXReceipts and MerkleProof Found")
utils.Logger().Info().Uint32("ToShardID", uint32(i)).Msg("[BroadcastCXReceipts] ReadCXReceipts and MerkleProof Found")
groupID := p2p.ShardID(i)
go node.host.SendMessageToGroups([]p2p.GroupID{p2p.NewGroupIDByShardID(groupID)}, host.ConstructP2pMessage(byte(0), proto_node.ConstructCXReceiptsMessage(cxReceipts, merkleProof)))
@ -630,7 +630,7 @@ func (node *Node) PostConsensusProcessing(newBlock *types.Block) {
// TODO: enable shard state update
//newBlockHeader := newBlock.Header()
//if newBlockHeader.ShardStateHash != (common.Hash{}) {
// if node.Consensus.ShardID == 0 {
// if node.Consensus.ShardIDs == 0 {
// // TODO ek – this is a temp hack until beacon chain sync is fixed
// // End-of-epoch block on beacon chain; block's EpochState is the
// // master resharding table. Broadcast it to the network.
@ -959,11 +959,11 @@ func (node *Node) epochShardStateMessageHandler(msgPayload []byte) error {
func (node *Node) transitionIntoNextEpoch(shardState types.ShardState) {
logger = logger.New(
"blsPubKey", hex.EncodeToString(node.Consensus.PubKey.Serialize()),
"curShard", node.Blockchain().ShardID(),
"curShard", node.Blockchain().ShardIDs(),
"curLeader", node.Consensus.IsLeader())
for _, c := range shardState {
utils.Logger().Debug().
Uint32("shardID", c.ShardID).
Uint32("shardID", c.ShardIDs).
Str("nodeList", c.NodeList).
Msg("new shard information")
}
@ -995,7 +995,7 @@ func (node *Node) transitionIntoNextEpoch(shardState types.ShardState) {
node.Consensus.UpdatePublicKeys(publicKeys)
// node.DRand.UpdatePublicKeys(publicKeys)
if node.Blockchain().ShardID() == myShardID {
if node.Blockchain().ShardIDs() == myShardID {
getLogger().Info("staying in the same shard")
} else {
getLogger().Info("moving to another shard")

@ -34,7 +34,7 @@ const (
GroupIDUnknown GroupID = "B1acKh0lE"
)
// ShardID defines the ID of a shard
// ShardIDs defines the ID of a shard
type ShardID uint32
// NewGroupIDByShardID returns a new groupID for a shard

Loading…
Cancel
Save