Fix incomingReceipts storage and some build failure

pull/1408/head
Rongjian Lan 5 years ago
parent cff71b332b
commit 964a7671a9
  1. 5
      api/service/syncing/syncing.go
  2. 2
      core/rawdb/accessors_chain.go
  3. 16
      core/types/block.go
  4. 2
      hmyclient/hmyclient.go
  5. 1
      node/node_error.go
  6. 4
      node/node_handler.go
  7. 1
      node/node_syncing.go
  8. 7
      test/chain/main.go

@ -544,7 +544,7 @@ func (ss *StateSync) updateBlockAndStatus(block *types.Block, bc *core.BlockChai
_, err := bc.InsertChain([]*types.Block{block})
if err != nil {
utils.Logger().Error().Err(err).Msgf("[SYNC] Error adding new block to blockchain %d %d %s", block.NumberU64(), block.ShardID(), block.IncomingReceipts())
utils.Logger().Error().Err(err).Msgf("[SYNC] Error adding new block to blockchain %d %d", block.NumberU64(), block.ShardID())
utils.Logger().Debug().Interface("block", bc.CurrentBlock()).Msg("[SYNC] Rolling back current block!")
bc.Rollback([]common.Hash{bc.CurrentBlock().Hash()})
@ -567,7 +567,6 @@ func (ss *StateSync) generateNewState(bc *core.BlockChain, worker *worker.Worker
// update blocks created before node start sync
parentHash := bc.CurrentBlock().Hash()
for {
utils.Logger().Warn().Msg("[SYNC] 111")
block := ss.getBlockFromOldBlocksByParentHash(parentHash)
if block == nil {
break
@ -585,7 +584,6 @@ func (ss *StateSync) generateNewState(bc *core.BlockChain, worker *worker.Worker
// update blocks after node start sync
parentHash = bc.CurrentBlock().Hash()
for {
utils.Logger().Warn().Msg("[SYNC] 222")
block := ss.getMaxConsensusBlockFromParentHash(parentHash)
if block == nil {
break
@ -608,7 +606,6 @@ func (ss *StateSync) generateNewState(bc *core.BlockChain, worker *worker.Worker
// update last mile blocks if any
parentHash = bc.CurrentBlock().Hash()
for {
utils.Logger().Warn().Msg("[SYNC] 333")
block := ss.getBlockFromLastMileBlocksByParentHash(parentHash)
if block == nil {
break

@ -339,7 +339,7 @@ func ReadBlock(db DatabaseReader, hash common.Hash, number uint64) *types.Block
if body == nil {
return nil
}
return types.NewBlockWithHeader(header).WithBody(body.Transactions, body.Uncles)
return types.NewBlockWithHeader(header).WithBody(body.Transactions, body.Uncles, body.IncomingReceipts)
}
// WriteBlock serializes a block into the database, header and body separately.

@ -154,8 +154,9 @@ func rlpHash(x interface{}) (h common.Hash) {
// Body is a simple (mutable, non-safe) data container for storing and moving
// a block's data contents (transactions and uncles) together.
type Body struct {
Transactions []*Transaction
Uncles []*Header
Transactions []*Transaction
Uncles []*Header
IncomingReceipts CXReceiptsProofs
}
// Block represents an entire block in the Ethereum blockchain.
@ -419,7 +420,7 @@ func (b *Block) Extra() []byte { return common.CopyBytes(b.header.Extra) }
func (b *Block) Header() *Header { return CopyHeader(b.header) }
// Body returns the non-header content of the block.
func (b *Block) Body() *Body { return &Body{b.transactions, b.uncles} }
func (b *Block) Body() *Body { return &Body{b.transactions, b.uncles, b.incomingReceipts} }
// Vdf returns header Vdf.
func (b *Block) Vdf() []byte { return common.CopyBytes(b.header.Vdf) }
@ -464,11 +465,12 @@ func (b *Block) WithSeal(header *Header) *Block {
}
// WithBody returns a new block with the given transaction and uncle contents.
func (b *Block) WithBody(transactions []*Transaction, uncles []*Header) *Block {
func (b *Block) WithBody(transactions []*Transaction, uncles []*Header, incomingReceipts CXReceiptsProofs) *Block {
block := &Block{
header: CopyHeader(b.header),
transactions: make([]*Transaction, len(transactions)),
uncles: make([]*Header, len(uncles)),
header: CopyHeader(b.header),
transactions: make([]*Transaction, len(transactions)),
uncles: make([]*Header, len(uncles)),
incomingReceipts: incomingReceipts,
}
copy(block.transactions, transactions)
for i := range uncles {

@ -119,7 +119,7 @@ func (c *Client) getBlock(ctx context.Context, method string, args ...interface{
}
txs[i] = tx.tx
}
return types.NewBlockWithHeader(head).WithBody(txs, []*types.Header{}), nil
return types.NewBlockWithHeader(head).WithBody(txs, []*types.Header{}, nil), nil
}
func toBlockNumArg(number *big.Int) string {

@ -5,5 +5,6 @@ import (
)
var (
// ErrCrosslinkVerificationFail ...
ErrCrosslinkVerificationFail = errors.New("Crosslink Verification Failed")
)

@ -179,7 +179,7 @@ func (node *Node) messageHandler(content []byte, sender libp2p_peer.ID) {
if block.ShardID() == 0 {
utils.Logger().Info().
Uint64("block", blocks[0].NumberU64()).
Msgf("Block being handled by block channel %d %d %s", block.NumberU64(), block.ShardID(), block.IncomingReceipts())
Msgf("Block being handled by block channel %d %d", block.NumberU64(), block.ShardID())
node.BeaconBlockChannel <- block
}
}
@ -281,7 +281,7 @@ func (node *Node) transactionMessageHandler(msgPayload []byte) {
// 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 *Node) BroadcastNewBlock(newBlock *types.Block) {
utils.Logger().Info().Msgf("broadcasting new block %d %s", newBlock.NumberU64(), newBlock.IncomingReceipts())
utils.Logger().Info().Msgf("broadcasting new block %d", newBlock.NumberU64())
groups := []p2p.GroupID{node.NodeConfig.GetClientGroupID()}
msg := host.ConstructP2pMessage(byte(0), proto_node.ConstructBlocksSyncMessage([]*types.Block{newBlock}))
if err := node.host.SendMessageToGroups(groups, msg); err != nil {

@ -360,6 +360,7 @@ func (node *Node) CalculateResponse(request *downloader_pb.DownloaderRequest, in
continue
}
encodedBlock, err := rlp.EncodeToBytes(block)
if err == nil {
response.Payload = append(response.Payload, encodedBlock)
}

@ -13,7 +13,6 @@ import (
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/params"
"github.com/harmony-one/harmony/consensus"
"github.com/harmony-one/harmony/core"
core_state "github.com/harmony-one/harmony/core/state"
"github.com/harmony-one/harmony/core/types"
@ -105,7 +104,7 @@ func fundFaucetContract(chain *core.BlockChain) {
fmt.Println("--------- Funding addresses for Faucet Contract Call ---------")
fmt.Println()
contractworker = pkgworker.New(params.TestChainConfig, chain, consensus.NewFaker(), 0)
contractworker = pkgworker.New(params.TestChainConfig, chain, chain.Engine(), 0)
nonce = contractworker.GetCurrentState().GetNonce(crypto.PubkeyToAddress(FaucetPriKey.PublicKey))
dataEnc = common.FromHex(FaucetContractBinary)
ftx, _ := types.SignTx(types.NewContractCreation(nonce, 0, big.NewInt(7000000000000000000), params.TxGasContractCreation*10, nil, dataEnc), types.HomesteadSigner{}, FaucetPriKey)
@ -331,7 +330,7 @@ func playStakingContract(chain *core.BlockChain) {
func main() {
genesis := gspec.MustCommit(database)
chain, _ := core.NewBlockChain(database, nil, gspec.Config, consensus.NewFaker(), vm.Config{}, nil)
chain, _ := core.NewBlockChain(database, nil, gspec.Config, chain.Engine(), vm.Config{}, nil)
txpool := core.NewTxPool(core.DefaultTxPoolConfig, chainConfig, chain)
@ -345,7 +344,7 @@ func main() {
//// Generate a small n-block chain and an uncle block for it
n := 3
if n > 0 {
blocks, _ := core.GenerateChain(chainConfig, genesis, consensus.NewFaker(), database, n, func(i int, gen *core.BlockGen) {
blocks, _ := core.GenerateChain(chainConfig, genesis, chain.Engine(), database, n, func(i int, gen *core.BlockGen) {
gen.SetCoinbase(FaucetAddress)
gen.SetShardID(0)
gen.AddTx(pendingTxs[i])

Loading…
Cancel
Save