From 02ba0b309ce666c62bb47cbba5500fcbcb5fae94 Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Thu, 5 Dec 2019 11:07:02 +0000 Subject: [PATCH] Fix cross-TX header introduction glitch Commit e79ba5fe880b56973a50a80d918b9145fce07cf0 introduced an off-by-one error which caused CX-enabled header to be introduced one epoch later than expected, i.e. at CrossTxEpoch + 1, where it should be CrossTxEpoch. This was caused by a vague, confusing naming of IsCrossTx(epoch) function of ChainConfig: The name did not clarify whether it meant introduction of CX-enabled header and processing of ingress receipts (which occurs at CrossTxEpoch) or acceptance of cross-shard transactions (which occurs at CrossTxEpoch+1). Introduce and use params.(*ChainConfig).HasCrossTxFields which handles the former case. --- block/factory/factory.go | 2 +- internal/params/config.go | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/block/factory/factory.go b/block/factory/factory.go index 6c3e3aac9..8de3fad0a 100644 --- a/block/factory/factory.go +++ b/block/factory/factory.go @@ -34,7 +34,7 @@ func (f *factory) NewHeader(epoch *big.Int) *block.Header { impl = v3.NewHeader() case f.chainConfig.IsCrossLink(epoch): impl = v2.NewHeader() - case f.chainConfig.IsCrossTx(epoch): + case f.chainConfig.HasCrossTxFields(epoch): impl = v1.NewHeader() default: impl = v0.NewHeader() diff --git a/internal/params/config.go b/internal/params/config.go index 5e5926426..99d6e23ec 100644 --- a/internal/params/config.go +++ b/internal/params/config.go @@ -139,21 +139,28 @@ func (c *ChainConfig) IsEIP155(epoch *big.Int) bool { return isForked(c.EIP155Epoch, epoch) } -// IsCrossTx returns whether cross-shard transaction is enabled in the given +// IsCrossTx returns whether cross-shard transaction is accepted in the given // epoch. // // 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 // ingress receipts. In other words, cross-shard transaction fields are -// introduced at CrossTxEpoch, but these fields are not used until -// CrossTxEpoch+1, when cross-shard transactions are actually accepted by the -// network. +// introduced and ingress receipts are processed at CrossTxEpoch, but the shard +// does not accept cross-shard transactions from clients until CrossTxEpoch+1. +// +// TODO ek – rename to AcceptsCrossTx to clarify func (c *ChainConfig) IsCrossTx(epoch *big.Int) bool { crossTxEpoch := new(big.Int).Add(c.CrossTxEpoch, common.Big1) 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 func (c *ChainConfig) IsStaking(epoch *big.Int) bool { return isForked(c.StakingEpoch, epoch)