fix incomingReceipts storage; cherry pick from RJ's branch

pull/1402/head
Rongjian Lan 5 years ago committed by chao
parent 7f62c8e57a
commit 261acf852f
  1. 2
      api/service/syncing/syncing.go
  2. 2
      core/rawdb/accessors_chain.go
  3. 16
      core/types/block.go
  4. 2
      hmyclient/hmyclient.go
  5. 2
      node/node_cross_shard.go
  6. 1
      node/node_error.go
  7. 9
      node/node_handler.go
  8. 1
      node/node_syncing.go
  9. 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).Msg("[SYNC] Error adding new block to blockchain")
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()})

@ -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 {

@ -119,7 +119,7 @@ func (node *Node) compareCrosslinkWithReceipts(cxp *types.CXReceiptsProof) error
if shardID == 0 {
block := beaconChain.GetBlockByNumber(blockNum)
if block == nil {
return ctxerror.New("[compareCrosslinkWithReceipts] Cannot get beaconchain heaer", "blockNum", blockNum, "shardID", shardID)
return ctxerror.New("[compareCrosslinkWithReceipts] Cannot get beaconchain header", "blockNum", blockNum, "shardID", shardID)
}
hash = block.Hash()
outgoingReceiptHash = block.OutgoingReceiptHash()

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

@ -179,7 +179,12 @@ func (node *Node) messageHandler(content []byte, sender libp2p_peer.ID) {
go node.ProcessCrossShardTx(blocks)
for _, block := range blocks {
node.BeaconBlockChannel <- block
if block.ShardID() == 0 {
utils.Logger().Info().
Uint64("block", blocks[0].NumberU64()).
Msgf("Block being handled by block channel %d %d", block.NumberU64(), block.ShardID())
node.BeaconBlockChannel <- block
}
}
}
if node.Client != nil && node.Client.UpdateBlocks != nil && blocks != nil {
@ -279,7 +284,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().Msg("broadcasting new block")
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