Fix cross-TX header introduction glitch

Commit e79ba5fe88 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.
pull/1964/head
Eugene Kim 5 years ago
parent a85a7d4a88
commit 02ba0b309c
  1. 2
      block/factory/factory.go
  2. 17
      internal/params/config.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()

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

Loading…
Cancel
Save