Skip to content

Commit

Permalink
Merge pull request #2292 from LeoHChen/s3_receiptlog_epoch
Browse files Browse the repository at this point in the history
S3 receiptlog epoch
  • Loading branch information
Leo Chen authored Feb 22, 2020
2 parents ab6a53a + 951fae0 commit ac4b6fc
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 32 deletions.
11 changes: 2 additions & 9 deletions core/block_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,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.
//
Expand Down Expand Up @@ -92,16 +89,12 @@ func (v *BlockValidator) ValidateState(block, parent *types.Block, statedb *stat
// 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.
// Skip the validation for it to avoid failure.
if rbloom != header.Bloom() && (block.NumberU64() != beaconBadBlock || 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]]))
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)
}

Expand Down
5 changes: 4 additions & 1 deletion core/state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,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
Expand Down
59 changes: 37 additions & 22 deletions internal/params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,33 @@ var EpochTBD = big.NewInt(10000000)
var (
// MainnetChainConfig is the chain parameters to run a node on the main network.
MainnetChainConfig = &ChainConfig{
ChainID: MainnetChainID,
CrossTxEpoch: big.NewInt(28),
CrossLinkEpoch: EpochTBD,
EIP155Epoch: big.NewInt(28),
S3Epoch: big.NewInt(28),
ChainID: MainnetChainID,
CrossTxEpoch: big.NewInt(28),
CrossLinkEpoch: 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.
TestnetChainConfig = &ChainConfig{
ChainID: TestnetChainID,
CrossTxEpoch: big.NewInt(1),
CrossLinkEpoch: big.NewInt(2),
EIP155Epoch: big.NewInt(0),
S3Epoch: big.NewInt(0),
ChainID: TestnetChainID,
CrossTxEpoch: big.NewInt(1),
CrossLinkEpoch: big.NewInt(2),
EIP155Epoch: big.NewInt(0),
S3Epoch: big.NewInt(0),
ReceiptLogEpoch: big.NewInt(0),
}

// PangaeaChainConfig contains the chain parameters for the Pangaea network.
// All features except for CrossLink are enabled at launch.
PangaeaChainConfig = &ChainConfig{
ChainID: PangaeaChainID,
CrossTxEpoch: big.NewInt(0),
CrossLinkEpoch: EpochTBD,
EIP155Epoch: big.NewInt(0),
S3Epoch: big.NewInt(0),
ChainID: PangaeaChainID,
CrossTxEpoch: big.NewInt(0),
CrossLinkEpoch: EpochTBD,
EIP155Epoch: big.NewInt(0),
S3Epoch: big.NewInt(0),
ReceiptLogEpoch: big.NewInt(0),
}

// AllProtocolChanges ...
Expand All @@ -58,6 +61,7 @@ var (
big.NewInt(0), // CrossLinkEpoch
big.NewInt(0), // EIP155Epoch
big.NewInt(0), // S3Epoch
big.NewInt(0), // ReceiptLogEpoch
}

// TestChainConfig ...
Expand All @@ -69,6 +73,7 @@ var (
big.NewInt(0), // CrossLinkEpoch
big.NewInt(0), // EIP155Epoch
big.NewInt(0), // S3Epoch
big.NewInt(0), // ReceiptLogEpoch
}

// TestRules ...
Expand Down Expand Up @@ -109,15 +114,19 @@ 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 CrossLink: %v}",
return fmt.Sprintf("{ChainID: %v EIP155: %v CrossTx: %v CrossLink: %v ReceiptLog: %v}",
c.ChainID,
c.EIP155Epoch,
c.CrossTxEpoch,
c.CrossLinkEpoch,
c.ReceiptLogEpoch,
)
}

Expand Down Expand Up @@ -151,6 +160,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.
Expand Down Expand Up @@ -259,8 +273,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.
Expand All @@ -270,9 +284,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),
}
}

0 comments on commit ac4b6fc

Please sign in to comment.