mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-22 03:30:37 +00:00
Skip gas limit checks for chains with gas limit contract (#7567)
Dirty hack to fix Chiado until #7151 is properly implemented. Should fix the following error: ``` [WARN] [05-23|17:07:39.303] Verification failed for header hash=0x4eee718e5958a862746ea9a9531a16e6a404698d3a0e8120e8aff743b9f1e0a2 height=1 err="invalid gas limit: have 12500000, want 10000000 +-= 9764" ```
This commit is contained in:
parent
faf62a0c11
commit
319e99e72a
@ -493,7 +493,11 @@ func (c *AuRa) VerifyHeader(chain consensus.ChainHeaderReader, header *types.Hea
|
||||
log.Error("consensus.ErrUnknownAncestor", "parentNum", number-1, "hash", header.ParentHash.String())
|
||||
return consensus.ErrUnknownAncestor
|
||||
}
|
||||
return ethash.VerifyHeaderBasics(chain, header, parent, false)
|
||||
return ethash.VerifyHeaderBasics(chain, header, parent, true /*checkTimestamp*/, c.HasGasLimitContract() /*skipGasLimit*/)
|
||||
}
|
||||
|
||||
func (c *AuRa) HasGasLimitContract() bool {
|
||||
return len(c.cfg.BlockRewardContractTransitions) != 0
|
||||
}
|
||||
|
||||
// nolint
|
||||
|
@ -461,7 +461,7 @@ func (c *Bor) verifyCascadingFields(chain consensus.ChainHeaderReader, header *t
|
||||
if err := misc.VerifyGaslimit(parent.GasLimit, header.GasLimit); err != nil {
|
||||
return err
|
||||
}
|
||||
} else if err := misc.VerifyEip1559Header(chain.Config(), parent, header); err != nil {
|
||||
} else if err := misc.VerifyEip1559Header(chain.Config(), parent, header, false /*skipGasLimit*/); err != nil {
|
||||
// Verify the header's EIP-1559 attributes.
|
||||
return err
|
||||
}
|
||||
|
@ -115,17 +115,10 @@ func (c *Clique) verifyCascadingFields(chain consensus.ChainHeaderReader, header
|
||||
if header.BaseFee != nil {
|
||||
return fmt.Errorf("invalid baseFee before fork: have %d, want <nil>", header.BaseFee)
|
||||
}
|
||||
// Verify that the gas limit remains within allowed bounds
|
||||
diff := int64(parent.GasLimit) - int64(header.GasLimit)
|
||||
if diff < 0 {
|
||||
diff *= -1
|
||||
if err := misc.VerifyGaslimit(parent.GasLimit, header.GasLimit); err != nil {
|
||||
return err
|
||||
}
|
||||
limit := parent.GasLimit / params.GasLimitBoundDivisor
|
||||
|
||||
if uint64(diff) >= limit || header.GasLimit < params.MinGasLimit {
|
||||
return fmt.Errorf("invalid gas limit: have %d, want %d += %d", header.GasLimit, parent.GasLimit, limit)
|
||||
}
|
||||
} else if err := misc.VerifyEip1559Header(chain.Config(), parent, header); err != nil {
|
||||
} else if err := misc.VerifyEip1559Header(chain.Config(), parent, header, false /*skipGasLimit*/); err != nil {
|
||||
// Verify the header's EIP-1559 attributes.
|
||||
return err
|
||||
}
|
||||
|
@ -197,13 +197,13 @@ func (ethash *Ethash) VerifyUncle(chain consensus.ChainHeaderReader, header *typ
|
||||
return ethash.verifyHeader(chain, uncle, ancestors[uncle.ParentHash], true, seal)
|
||||
}
|
||||
|
||||
func VerifyHeaderBasics(chain consensus.ChainHeaderReader, header, parent *types.Header, uncle bool) error {
|
||||
func VerifyHeaderBasics(chain consensus.ChainHeaderReader, header, parent *types.Header, checkTimestamp, skipGasLimit bool) error {
|
||||
// Ensure that the header's extra-data section is of a reasonable size
|
||||
if uint64(len(header.Extra)) > params.MaximumExtraDataSize {
|
||||
return fmt.Errorf("extra-data too long: %d > %d", len(header.Extra), params.MaximumExtraDataSize)
|
||||
}
|
||||
// Verify the header's timestamp
|
||||
if !uncle {
|
||||
if checkTimestamp {
|
||||
unixNow := time.Now().Unix()
|
||||
if header.Time > uint64(unixNow+allowedFutureBlockTimeSeconds) {
|
||||
return consensus.ErrFutureBlock
|
||||
@ -226,16 +226,12 @@ func VerifyHeaderBasics(chain consensus.ChainHeaderReader, header, parent *types
|
||||
if header.BaseFee != nil {
|
||||
return fmt.Errorf("invalid baseFee before fork: have %d, expected 'nil'", header.BaseFee)
|
||||
}
|
||||
// Verify that the gas limit remains within allowed bounds
|
||||
diff := int64(parent.GasLimit) - int64(header.GasLimit)
|
||||
if diff < 0 {
|
||||
diff *= -1
|
||||
if !skipGasLimit {
|
||||
if err := misc.VerifyGaslimit(parent.GasLimit, header.GasLimit); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
limit := parent.GasLimit / params.GasLimitBoundDivisor
|
||||
if uint64(diff) >= limit || header.GasLimit < params.MinGasLimit {
|
||||
return fmt.Errorf("invalid gas limit: have %d, want %d += %d", header.GasLimit, parent.GasLimit, limit)
|
||||
}
|
||||
} else if err := misc.VerifyEip1559Header(chain.Config(), parent, header); err != nil {
|
||||
} else if err := misc.VerifyEip1559Header(chain.Config(), parent, header, skipGasLimit); err != nil {
|
||||
// Verify the header's EIP-1559 attributes.
|
||||
return err
|
||||
}
|
||||
@ -263,7 +259,7 @@ func VerifyHeaderBasics(chain consensus.ChainHeaderReader, header, parent *types
|
||||
// stock Ethereum ethash engine.
|
||||
// See YP section 4.3.4. "Block Header Validity"
|
||||
func (ethash *Ethash) verifyHeader(chain consensus.ChainHeaderReader, header, parent *types.Header, uncle bool, seal bool) error {
|
||||
if err := VerifyHeaderBasics(chain, header, parent, uncle); err != nil {
|
||||
if err := VerifyHeaderBasics(chain, header, parent, !uncle /*checkTimestamp*/, false /*skipGasLimit*/); err != nil {
|
||||
return err
|
||||
}
|
||||
// Verify the block's difficulty based on its timestamp and parent's difficulty
|
||||
|
@ -237,7 +237,11 @@ func (s *Merge) verifyHeader(chain consensus.ChainHeaderReader, header, parent *
|
||||
return errInvalidUncleHash
|
||||
}
|
||||
|
||||
if err := misc.VerifyEip1559Header(chain.Config(), parent, header); err != nil {
|
||||
skipGasLimit := false
|
||||
if auraEngine, ok := s.eth1Engine.(*aura.AuRa); ok {
|
||||
skipGasLimit = auraEngine.HasGasLimitContract()
|
||||
}
|
||||
if err := misc.VerifyEip1559Header(chain.Config(), parent, header, skipGasLimit); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -31,14 +31,16 @@ import (
|
||||
// VerifyEip1559Header verifies some header attributes which were changed in EIP-1559,
|
||||
// - gas limit check
|
||||
// - basefee check
|
||||
func VerifyEip1559Header(config *chain.Config, parent, header *types.Header) error {
|
||||
// Verify that the gas limit remains within allowed bounds
|
||||
parentGasLimit := parent.GasLimit
|
||||
if !config.IsLondon(parent.Number.Uint64()) {
|
||||
parentGasLimit = parent.GasLimit * params.ElasticityMultiplier
|
||||
}
|
||||
if err := VerifyGaslimit(parentGasLimit, header.GasLimit); err != nil {
|
||||
return err
|
||||
func VerifyEip1559Header(config *chain.Config, parent, header *types.Header, skipGasLimit bool) error {
|
||||
if !skipGasLimit {
|
||||
// Verify that the gas limit remains within allowed bounds
|
||||
parentGasLimit := parent.GasLimit
|
||||
if !config.IsLondon(parent.Number.Uint64()) {
|
||||
parentGasLimit = parent.GasLimit * params.ElasticityMultiplier
|
||||
}
|
||||
if err := VerifyGaslimit(parentGasLimit, header.GasLimit); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
// Verify the header is not malformed
|
||||
if header.BaseFee == nil {
|
||||
|
@ -80,7 +80,7 @@ func TestBlockGasLimits(t *testing.T) {
|
||||
BaseFee: initial,
|
||||
Number: big.NewInt(tc.pNum + 1),
|
||||
}
|
||||
err := VerifyEip1559Header(config(), parent, header)
|
||||
err := VerifyEip1559Header(config(), parent, header, false /*skipGasLimit*/)
|
||||
if tc.ok && err != nil {
|
||||
t.Errorf("test %d: Expected valid header: %s", i, err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user