From 28cb1e809a1503fa8ec42f1913a00e718cb1c5d7 Mon Sep 17 00:00:00 2001 From: Leo Chen Date: Sat, 22 Feb 2020 01:41:47 +0000 Subject: [PATCH 1/3] Revert "Merge pull request #2202 from rlan35/s3" This reverts commit 2cfc6d074d2cdb0d26309d2c4650c8d45dac1ac0, reversing changes made to 5f114872ce25020acc54f26021ca7f383a5322ca. --- core/block_validator.go | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/core/block_validator.go b/core/block_validator.go index 2ffb85e3b..0df9e2dc6 100644 --- a/core/block_validator.go +++ b/core/block_validator.go @@ -34,9 +34,6 @@ import ( "github.com/harmony-one/harmony/internal/params" ) -// Beacon chain block 1213181 is a one-off block with empty receipts which is expected to be non-empty. -const beaconBadBlock = 1213181 - // BlockValidator is responsible for validating block headers, uncles and // processed state. // @@ -96,16 +93,14 @@ func (v *BlockValidator) ValidateState(block *types.Block, statedb *state.DB, re // Validate the received block's bloom with the one derived from the generated receipts. // For valid blocks this should always validate to true. rbloom := types.CreateBloom(receipts) - // Beacon chain block 1213181 is a one-off block with empty receipts which is expected to be non-empty. + // Beacon chain block 1213181 is a one-off block with empty bloom which is expected to be non-empty. // Skip the validation for it to avoid failure. - if rbloom != header.Bloom() && (block.NumberU64() != beaconBadBlock || block.ShardID() != 0) { + if rbloom != header.Bloom() && (block.NumberU64() != 1213181 || block.ShardID() != 0) { return fmt.Errorf("invalid bloom (remote: %x local: %x)", header.Bloom(), rbloom) } // Tre receipt Trie's root (R = (Tr [[H1, R1], ... [Hn, R1]])) receiptSha := types.DeriveSha(receipts) - // Beacon chain block 1213181 is a one-off block with empty receipts which is expected to be non-empty. - // Skip the validation for it to avoid failure. - if receiptSha != header.ReceiptHash() && (block.NumberU64() != beaconBadBlock || block.ShardID() != 0) { + if receiptSha != header.ReceiptHash() { return fmt.Errorf("invalid receipt root hash (remote: %x local: %x)", header.ReceiptHash(), receiptSha) } From 6ca2d8fc6417bff93e1f44e9c1169b57e159ad91 Mon Sep 17 00:00:00 2001 From: Leo Chen Date: Sat, 22 Feb 2020 01:42:02 +0000 Subject: [PATCH 2/3] Revert "Merge pull request #2184 from rlan35/s3" This reverts commit 5f114872ce25020acc54f26021ca7f383a5322ca, reversing changes made to b4ddb94b9157a4512e48d9a224d8d957fc82c697. --- core/block_validator.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/core/block_validator.go b/core/block_validator.go index 0df9e2dc6..716a0b641 100644 --- a/core/block_validator.go +++ b/core/block_validator.go @@ -93,9 +93,7 @@ func (v *BlockValidator) ValidateState(block *types.Block, statedb *state.DB, re // Validate the received block's bloom with the one derived from the generated receipts. // For valid blocks this should always validate to true. rbloom := types.CreateBloom(receipts) - // Beacon chain block 1213181 is a one-off block with empty bloom which is expected to be non-empty. - // Skip the validation for it to avoid failure. - if rbloom != header.Bloom() && (block.NumberU64() != 1213181 || block.ShardID() != 0) { + if rbloom != header.Bloom() { return fmt.Errorf("invalid bloom (remote: %x local: %x)", header.Bloom(), rbloom) } // Tre receipt Trie's root (R = (Tr [[H1, R1], ... [Hn, R1]])) From db36fd2280488d8675019e889fc79292e47c17a4 Mon Sep 17 00:00:00 2001 From: Leo Chen Date: Sat, 22 Feb 2020 01:33:24 +0000 Subject: [PATCH 3/3] [config] add ReceiptLogEpoch Signed-off-by: Leo Chen --- core/state_processor.go | 5 ++++- internal/params/config.go | 30 +++++++++++++++++++++++------- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/core/state_processor.go b/core/state_processor.go index f7fbe0a60..1af96b3b7 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -188,8 +188,11 @@ func ApplyTransaction(config *params.ChainConfig, bc ChainContext, author *commo if msg.To() == nil { receipt.ContractAddress = crypto.CreateAddress(vmenv.Context.Origin, tx.Nonce()) } + // Set the receipt logs and create a bloom for filtering - receipt.Logs = statedb.GetLogs(tx.Hash()) + if config.IsReceiptLog(header.Epoch()) { + receipt.Logs = statedb.GetLogs(tx.Hash()) + } receipt.Bloom = types.CreateBloom(types.Receipts{receipt}) var cxReceipt *types.CXReceipt diff --git a/internal/params/config.go b/internal/params/config.go index 3854f5746..2a8dedcc1 100644 --- a/internal/params/config.go +++ b/internal/params/config.go @@ -30,6 +30,7 @@ var ( PreStakingEpoch: EpochTBD, EIP155Epoch: big.NewInt(28), S3Epoch: big.NewInt(28), + ReceiptLogEpoch: big.NewInt(101), } // TestnetChainConfig contains the chain parameters to run a node on the harmony test network. @@ -41,6 +42,7 @@ var ( PreStakingEpoch: big.NewInt(2), EIP155Epoch: big.NewInt(0), S3Epoch: big.NewInt(0), + ReceiptLogEpoch: big.NewInt(0), } // PangaeaChainConfig contains the chain parameters for the Pangaea network. @@ -53,6 +55,7 @@ var ( PreStakingEpoch: big.NewInt(0), EIP155Epoch: big.NewInt(0), S3Epoch: big.NewInt(0), + ReceiptLogEpoch: big.NewInt(0), } // LocalnetChainConfig contains the chain parameters to run for local development. @@ -64,6 +67,7 @@ var ( PreStakingEpoch: big.NewInt(2), EIP155Epoch: big.NewInt(0), S3Epoch: big.NewInt(0), + ReceiptLogEpoch: big.NewInt(0), } // AllProtocolChanges ... @@ -77,6 +81,7 @@ var ( big.NewInt(0), // PreStakingEpoch big.NewInt(0), // EIP155Epoch big.NewInt(0), // S3Epoch + big.NewInt(0), // ReceiptLogEpoch } // TestChainConfig ... @@ -90,6 +95,7 @@ var ( big.NewInt(0), // PreStakingEpoch big.NewInt(0), // EIP155Epoch big.NewInt(0), // S3Epoch + big.NewInt(0), // ReceiptLogEpoch } // TestRules ... @@ -136,16 +142,20 @@ type ChainConfig struct { // S3 epoch is the first epoch containing S3 mainnet and all ethereum update up to Constantinople S3Epoch *big.Int `json:"s3-epoch,omitempty"` + + // ReceiptLogEpoch is the first epoch support receiptlog + ReceiptLogEpoch *big.Int `json:"receipt-log-epoch,omitempty"` } // String implements the fmt.Stringer interface. func (c *ChainConfig) String() string { - return fmt.Sprintf("{ChainID: %v EIP155: %v CrossTx: %v Staking: %v CrossLink: %v}", + return fmt.Sprintf("{ChainID: %v EIP155: %v CrossTx: %v Staking: %v CrossLink: %v ReceiptLog: %v}", c.ChainID, c.EIP155Epoch, c.CrossTxEpoch, c.StakingEpoch, c.CrossLinkEpoch, + c.ReceiptLogEpoch, ) } @@ -194,6 +204,11 @@ func (c *ChainConfig) IsS3(epoch *big.Int) bool { return isForked(c.S3Epoch, epoch) } +// IsReceiptLog returns whether epoch is either equal to the ReceiptLog fork epoch or greater. +func (c *ChainConfig) IsReceiptLog(epoch *big.Int) bool { + return isForked(c.ReceiptLogEpoch, epoch) +} + // GasTable returns the gas table corresponding to the current phase (homestead or homestead reprice). // // The returned GasTable's fields shouldn't, under any circumstances, be changed. @@ -302,8 +317,8 @@ func (err *ConfigCompatError) Error() string { // Rules is a one time interface meaning that it shouldn't be used in between transition // phases. type Rules struct { - ChainID *big.Int - IsCrossLink, IsEIP155, IsS3 bool + ChainID *big.Int + IsCrossLink, IsEIP155, IsS3, IsReceiptLog bool } // Rules ensures c's ChainID is not nil. @@ -313,9 +328,10 @@ func (c *ChainConfig) Rules(epoch *big.Int) Rules { chainID = new(big.Int) } return Rules{ - ChainID: new(big.Int).Set(chainID), - IsCrossLink: c.IsCrossLink(epoch), - IsEIP155: c.IsEIP155(epoch), - IsS3: c.IsS3(epoch), + ChainID: new(big.Int).Set(chainID), + IsCrossLink: c.IsCrossLink(epoch), + IsEIP155: c.IsEIP155(epoch), + IsS3: c.IsS3(epoch), + IsReceiptLog: c.IsReceiptLog(epoch), } }