mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-22 11:41:19 +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())
|
log.Error("consensus.ErrUnknownAncestor", "parentNum", number-1, "hash", header.ParentHash.String())
|
||||||
return consensus.ErrUnknownAncestor
|
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
|
// nolint
|
||||||
|
@ -461,7 +461,7 @@ func (c *Bor) verifyCascadingFields(chain consensus.ChainHeaderReader, header *t
|
|||||||
if err := misc.VerifyGaslimit(parent.GasLimit, header.GasLimit); err != nil {
|
if err := misc.VerifyGaslimit(parent.GasLimit, header.GasLimit); err != nil {
|
||||||
return err
|
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.
|
// Verify the header's EIP-1559 attributes.
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -115,17 +115,10 @@ func (c *Clique) verifyCascadingFields(chain consensus.ChainHeaderReader, header
|
|||||||
if header.BaseFee != nil {
|
if header.BaseFee != nil {
|
||||||
return fmt.Errorf("invalid baseFee before fork: have %d, want <nil>", header.BaseFee)
|
return fmt.Errorf("invalid baseFee before fork: have %d, want <nil>", header.BaseFee)
|
||||||
}
|
}
|
||||||
// Verify that the gas limit remains within allowed bounds
|
if err := misc.VerifyGaslimit(parent.GasLimit, header.GasLimit); err != nil {
|
||||||
diff := int64(parent.GasLimit) - int64(header.GasLimit)
|
return err
|
||||||
if diff < 0 {
|
|
||||||
diff *= -1
|
|
||||||
}
|
}
|
||||||
limit := parent.GasLimit / params.GasLimitBoundDivisor
|
} else if err := misc.VerifyEip1559Header(chain.Config(), parent, header, false /*skipGasLimit*/); err != nil {
|
||||||
|
|
||||||
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 {
|
|
||||||
// Verify the header's EIP-1559 attributes.
|
// Verify the header's EIP-1559 attributes.
|
||||||
return err
|
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)
|
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
|
// Ensure that the header's extra-data section is of a reasonable size
|
||||||
if uint64(len(header.Extra)) > params.MaximumExtraDataSize {
|
if uint64(len(header.Extra)) > params.MaximumExtraDataSize {
|
||||||
return fmt.Errorf("extra-data too long: %d > %d", len(header.Extra), params.MaximumExtraDataSize)
|
return fmt.Errorf("extra-data too long: %d > %d", len(header.Extra), params.MaximumExtraDataSize)
|
||||||
}
|
}
|
||||||
// Verify the header's timestamp
|
// Verify the header's timestamp
|
||||||
if !uncle {
|
if checkTimestamp {
|
||||||
unixNow := time.Now().Unix()
|
unixNow := time.Now().Unix()
|
||||||
if header.Time > uint64(unixNow+allowedFutureBlockTimeSeconds) {
|
if header.Time > uint64(unixNow+allowedFutureBlockTimeSeconds) {
|
||||||
return consensus.ErrFutureBlock
|
return consensus.ErrFutureBlock
|
||||||
@ -226,16 +226,12 @@ func VerifyHeaderBasics(chain consensus.ChainHeaderReader, header, parent *types
|
|||||||
if header.BaseFee != nil {
|
if header.BaseFee != nil {
|
||||||
return fmt.Errorf("invalid baseFee before fork: have %d, expected 'nil'", header.BaseFee)
|
return fmt.Errorf("invalid baseFee before fork: have %d, expected 'nil'", header.BaseFee)
|
||||||
}
|
}
|
||||||
// Verify that the gas limit remains within allowed bounds
|
if !skipGasLimit {
|
||||||
diff := int64(parent.GasLimit) - int64(header.GasLimit)
|
if err := misc.VerifyGaslimit(parent.GasLimit, header.GasLimit); err != nil {
|
||||||
if diff < 0 {
|
return err
|
||||||
diff *= -1
|
|
||||||
}
|
}
|
||||||
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.
|
// Verify the header's EIP-1559 attributes.
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -263,7 +259,7 @@ func VerifyHeaderBasics(chain consensus.ChainHeaderReader, header, parent *types
|
|||||||
// stock Ethereum ethash engine.
|
// stock Ethereum ethash engine.
|
||||||
// See YP section 4.3.4. "Block Header Validity"
|
// 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 {
|
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
|
return err
|
||||||
}
|
}
|
||||||
// Verify the block's difficulty based on its timestamp and parent's difficulty
|
// 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
|
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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +31,8 @@ import (
|
|||||||
// VerifyEip1559Header verifies some header attributes which were changed in EIP-1559,
|
// VerifyEip1559Header verifies some header attributes which were changed in EIP-1559,
|
||||||
// - gas limit check
|
// - gas limit check
|
||||||
// - basefee check
|
// - basefee check
|
||||||
func VerifyEip1559Header(config *chain.Config, parent, header *types.Header) error {
|
func VerifyEip1559Header(config *chain.Config, parent, header *types.Header, skipGasLimit bool) error {
|
||||||
|
if !skipGasLimit {
|
||||||
// Verify that the gas limit remains within allowed bounds
|
// Verify that the gas limit remains within allowed bounds
|
||||||
parentGasLimit := parent.GasLimit
|
parentGasLimit := parent.GasLimit
|
||||||
if !config.IsLondon(parent.Number.Uint64()) {
|
if !config.IsLondon(parent.Number.Uint64()) {
|
||||||
@ -40,6 +41,7 @@ func VerifyEip1559Header(config *chain.Config, parent, header *types.Header) err
|
|||||||
if err := VerifyGaslimit(parentGasLimit, header.GasLimit); err != nil {
|
if err := VerifyGaslimit(parentGasLimit, header.GasLimit); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// Verify the header is not malformed
|
// Verify the header is not malformed
|
||||||
if header.BaseFee == nil {
|
if header.BaseFee == nil {
|
||||||
return fmt.Errorf("header is missing baseFee")
|
return fmt.Errorf("header is missing baseFee")
|
||||||
|
@ -80,7 +80,7 @@ func TestBlockGasLimits(t *testing.T) {
|
|||||||
BaseFee: initial,
|
BaseFee: initial,
|
||||||
Number: big.NewInt(tc.pNum + 1),
|
Number: big.NewInt(tc.pNum + 1),
|
||||||
}
|
}
|
||||||
err := VerifyEip1559Header(config(), parent, header)
|
err := VerifyEip1559Header(config(), parent, header, false /*skipGasLimit*/)
|
||||||
if tc.ok && err != nil {
|
if tc.ok && err != nil {
|
||||||
t.Errorf("test %d: Expected valid header: %s", i, err)
|
t.Errorf("test %d: Expected valid header: %s", i, err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user