Skip to content

Commit

Permalink
Update finalized header when begin block hook is called
Browse files Browse the repository at this point in the history
  • Loading branch information
Eduard-Voiculescu committed Oct 4, 2024
1 parent 5376e54 commit 65f117b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
22 changes: 16 additions & 6 deletions x/evm/keeper/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package keeper

import (
sdk "github.com/cosmos/cosmos-sdk/types"
ethcommon "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/tracing"
"github.com/ethereum/go-ethereum/core/types"
"math/big"
Expand All @@ -33,15 +34,24 @@ func (k *Keeper) BeginBlock(ctx sdk.Context) error {

if k.evmTracer != nil && k.evmTracer.OnBlockStart != nil {
b := types.NewBlock(&types.Header{
Number: big.NewInt(ctx.BlockHeight()),
Time: uint64(ctx.BlockTime().Unix()),
Number: big.NewInt(ctx.BlockHeight()),
Time: uint64(ctx.BlockTime().Unix()),
ParentHash: ethcommon.BytesToHash(ctx.BlockHeader().LastBlockId.Hash),
}, nil, nil, nil)

finalizedHeaderNumber := ctx.BlockHeight() - 1
if ctx.BlockHeight() == 0 {
finalizedHeaderNumber = 0
}

finalizedHeader := &types.Header{
Number: big.NewInt(finalizedHeaderNumber),
}

k.evmTracer.OnBlockStart(tracing.BlockEvent{
Block: b,
TD: big.NewInt(1),
// Finalized: , // todo: how to set up the header here?
// Safe: , // todo: how to set up the header here?
Block: b,
TD: big.NewInt(1),
Finalized: finalizedHeader,
})
}

Expand Down
4 changes: 0 additions & 4 deletions x/evm/tracers/firehose.go
Original file line number Diff line number Diff line change
Expand Up @@ -1444,10 +1444,6 @@ func (f *Firehose) printBlockToFirehose(block *pbeth.Block, finalityStatus *Fina
}
}

if block.Number-libNum >= 200 {
libNum = block.Number - 200
}

// **Important* The final space in the Sprintf template is mandatory!
f.outputBuffer.WriteString(fmt.Sprintf("FIRE BLOCK %d %s %d %s %d %d ", block.Number, hex.EncodeToString(block.Hash), previousNum, previousHash, libNum, block.Time().UnixNano()))

Expand Down

0 comments on commit 65f117b

Please sign in to comment.