add validation and logs around prague1 checks

This commit is contained in:
Cal Bera 2025-08-06 11:07:39 -07:00
parent 365217f04d
commit 88db0d12fa
2 changed files with 18 additions and 5 deletions

View file

@ -21,10 +21,11 @@ import (
"fmt"
"math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/davecgh/go-spew/spew"
"github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/trie"
)
@ -90,7 +91,7 @@ func (v *BlockValidator) ValidateBody(block *types.Block) error {
// Berachain: Pre-compute expected PoL tx hash when in Prague1.
isPrague1 := v.config.IsPrague1(block.Number(), block.Time())
var expectedPoLHash common.Hash
var expectedPoLTx *types.Transaction
if isPrague1 {
if block.ProposerPubkey() == nil {
return errors.New("post-prague1 block missing parent proposer pubkey")
@ -107,7 +108,7 @@ func (v *BlockValidator) ValidateBody(block *types.Block) error {
if err != nil {
return fmt.Errorf("failed to create expected PoL tx: %w", err)
}
expectedPoLHash = polTx.Hash()
expectedPoLTx = polTx
// Validate that the block has at least one tx.
if len(txs) == 0 {
@ -121,8 +122,10 @@ func (v *BlockValidator) ValidateBody(block *types.Block) error {
// Berachain: validate the PoL tx is only the first tx in the block.
switch {
case isPrague1 && i == 0:
if tx.Hash() != expectedPoLHash {
return fmt.Errorf("PoL tx hash mismatch: have %v, want %v", tx.Hash(), expectedPoLHash)
if tx.Hash() != expectedPoLTx.Hash() {
log.Debug("PoL tx hash mismatch", "have", tx.Hash(), "expected", expectedPoLTx.Hash())
log.Debug("PoL tx contents", "have", spew.Sdump(tx), "expected", spew.Sdump(expectedPoLTx))
return fmt.Errorf("PoL tx hash mismatch: have %v, want %v", tx.Hash(), expectedPoLTx.Hash())
}
case tx.Type() == types.PoLTxType:
return fmt.Errorf("invalid block: tx at index %d is a PoL tx", i)

View file

@ -994,6 +994,16 @@ func (c *ChainConfig) CheckConfigForkOrder() error {
}
}
}
// Berachain: Check that Prague1 is configured correctly if it is enabled.
if c.Berachain.Prague1.Time != nil {
if c.Berachain.Prague1.PoLDistributorAddress == (common.Address{}) {
return fmt.Errorf("invalid chain configuration: missing PoL distributor address for Prague1 fork")
}
if c.Berachain.Prague1.BaseFeeChangeDenominator == 0 {
return fmt.Errorf("invalid chain configuration: base fee change denominator must be > 0 for Prague1 fork")
}
}
return nil
}