Merge pull request #1964 from harmony-ek/fix_cross_tx_epoch_handling

Fix CrossTxEpoch handling
pull/1972/head
Eugene Kim 5 years ago committed by GitHub
commit 2158d4d828
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      block/factory/factory.go
  2. 4
      core/block_validator.go
  3. 2
      core/blockchain.go
  4. 4
      core/state_processor.go
  5. 19
      internal/params/config.go
  6. 2
      node/node_newblock.go

@ -34,7 +34,7 @@ func (f *factory) NewHeader(epoch *big.Int) *block.Header {
impl = v3.NewHeader() impl = v3.NewHeader()
case f.chainConfig.IsCrossLink(epoch): case f.chainConfig.IsCrossLink(epoch):
impl = v2.NewHeader() impl = v2.NewHeader()
case f.chainConfig.IsCrossTx(epoch): case f.chainConfig.HasCrossTxFields(epoch):
impl = v1.NewHeader() impl = v1.NewHeader()
default: default:
impl = v0.NewHeader() impl = v0.NewHeader()

@ -100,7 +100,7 @@ func (v *BlockValidator) ValidateState(block, parent *types.Block, statedb *stat
return fmt.Errorf("invalid receipt root hash (remote: %x local: %x)", header.ReceiptHash(), receiptSha) return fmt.Errorf("invalid receipt root hash (remote: %x local: %x)", header.ReceiptHash(), receiptSha)
} }
if v.config.IsCrossTx(block.Epoch()) { if v.config.HasCrossTxFields(block.Epoch()) {
cxsSha := types.DeriveMultipleShardsSha(cxReceipts) cxsSha := types.DeriveMultipleShardsSha(cxReceipts)
if cxsSha != header.OutgoingReceiptHash() { if cxsSha != header.OutgoingReceiptHash() {
return fmt.Errorf("invalid cross shard receipt root hash (remote: %x local: %x)", header.OutgoingReceiptHash(), cxsSha) return fmt.Errorf("invalid cross shard receipt root hash (remote: %x local: %x)", header.OutgoingReceiptHash(), cxsSha)
@ -175,7 +175,7 @@ func CalcGasLimit(parent *types.Block, gasFloor, gasCeil uint64) uint64 {
// ValidateCXReceiptsProof checks whether the given CXReceiptsProof is consistency with itself // ValidateCXReceiptsProof checks whether the given CXReceiptsProof is consistency with itself
func (v *BlockValidator) ValidateCXReceiptsProof(cxp *types.CXReceiptsProof) error { func (v *BlockValidator) ValidateCXReceiptsProof(cxp *types.CXReceiptsProof) error {
if !v.config.IsCrossTx(cxp.Header.Epoch()) { if !v.config.AcceptsCrossTx(cxp.Header.Epoch()) {
return ctxerror.New("[ValidateCXReceiptsProof] cross shard receipt received before cx fork") return ctxerror.New("[ValidateCXReceiptsProof] cross shard receipt received before cx fork")
} }

@ -1102,7 +1102,7 @@ func (bc *BlockChain) WriteBlockWithState(
//// Cross-shard txns //// Cross-shard txns
epoch := block.Header().Epoch() epoch := block.Header().Epoch()
if bc.chainConfig.IsCrossTx(block.Epoch()) { if bc.chainConfig.HasCrossTxFields(block.Epoch()) {
shardingConfig := shard.Schedule.InstanceForEpoch(epoch) shardingConfig := shard.Schedule.InstanceForEpoch(epoch)
shardNum := int(shardingConfig.NumShards()) shardNum := int(shardingConfig.NumShards())
for i := 0; i < shardNum; i++ { for i := 0; i < shardNum; i++ {

@ -122,7 +122,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.DB, cfg vm.C
// return true if it is valid // return true if it is valid
func getTransactionType(config *params.ChainConfig, header *block.Header, tx *types.Transaction) types.TransactionType { func getTransactionType(config *params.ChainConfig, header *block.Header, tx *types.Transaction) types.TransactionType {
if header.ShardID() == tx.ShardID() && (!config.IsCrossTx(header.Epoch()) || tx.ShardID() == tx.ToShardID()) { if header.ShardID() == tx.ShardID() && (!config.AcceptsCrossTx(header.Epoch()) || tx.ShardID() == tx.ToShardID()) {
return types.SameShardTx return types.SameShardTx
} }
numShards := shard.Schedule.InstanceForEpoch(header.Epoch()).NumShards() numShards := shard.Schedule.InstanceForEpoch(header.Epoch()).NumShards()
@ -143,7 +143,7 @@ func ApplyTransaction(config *params.ChainConfig, bc ChainContext, author *commo
return nil, nil, 0, fmt.Errorf("Invalid Transaction Type") return nil, nil, 0, fmt.Errorf("Invalid Transaction Type")
} }
if txType != types.SameShardTx && !config.IsCrossTx(header.Epoch()) { if txType != types.SameShardTx && !config.AcceptsCrossTx(header.Epoch()) {
return nil, nil, 0, fmt.Errorf( return nil, nil, 0, fmt.Errorf(
"cannot handle cross-shard transaction until after epoch %v (now %v)", "cannot handle cross-shard transaction until after epoch %v (now %v)",
config.CrossTxEpoch, header.Epoch()) config.CrossTxEpoch, header.Epoch())

@ -139,21 +139,26 @@ func (c *ChainConfig) IsEIP155(epoch *big.Int) bool {
return isForked(c.EIP155Epoch, epoch) return isForked(c.EIP155Epoch, epoch)
} }
// IsCrossTx returns whether cross-shard transaction is enabled in the given // AcceptsCrossTx returns whether cross-shard transaction is accepted in the
// epoch. // given epoch.
// //
// Note that this is different from comparing epoch against CrossTxEpoch. // Note that this is different from comparing epoch against CrossTxEpoch.
// Cross-shard transaction is enabled from CrossTxEpoch+1 and on, in order to // Cross-shard transaction is accepted from CrossTxEpoch+1 and on, in order to
// allow for all shards to roll into CrossTxEpoch and become able to handle // allow for all shards to roll into CrossTxEpoch and become able to handle
// ingress receipts. In other words, cross-shard transaction fields are // ingress receipts. In other words, cross-shard transaction fields are
// introduced at CrossTxEpoch, but these fields are not used until // introduced and ingress receipts are processed at CrossTxEpoch, but the shard
// CrossTxEpoch+1, when cross-shard transactions are actually accepted by the // does not accept cross-shard transactions from clients until CrossTxEpoch+1.
// network. func (c *ChainConfig) AcceptsCrossTx(epoch *big.Int) bool {
func (c *ChainConfig) IsCrossTx(epoch *big.Int) bool {
crossTxEpoch := new(big.Int).Add(c.CrossTxEpoch, common.Big1) crossTxEpoch := new(big.Int).Add(c.CrossTxEpoch, common.Big1)
return isForked(crossTxEpoch, epoch) return isForked(crossTxEpoch, epoch)
} }
// HasCrossTxFields returns whether blocks in the given epoch includes
// cross-shard transaction fields.
func (c *ChainConfig) HasCrossTxFields(epoch *big.Int) bool {
return isForked(c.CrossTxEpoch, epoch)
}
// IsStaking determines whether it is staking epoch // IsStaking determines whether it is staking epoch
func (c *ChainConfig) IsStaking(epoch *big.Int) bool { func (c *ChainConfig) IsStaking(epoch *big.Int) bool {
return isForked(c.StakingEpoch, epoch) return isForked(c.StakingEpoch, epoch)

@ -167,7 +167,7 @@ func (node *Node) proposeNewBlock() (*types.Block, error) {
} }
func (node *Node) proposeReceiptsProof() []*types.CXReceiptsProof { func (node *Node) proposeReceiptsProof() []*types.CXReceiptsProof {
if !node.Blockchain().Config().IsCrossTx(node.Worker.GetCurrentHeader().Epoch()) { if !node.Blockchain().Config().HasCrossTxFields(node.Worker.GetCurrentHeader().Epoch()) {
return []*types.CXReceiptsProof{} return []*types.CXReceiptsProof{}
} }

Loading…
Cancel
Save