forked from crypto-org-chain/ethermint
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update tracer with custom OnCosmosBlockStart and OnCosmosBlockEnd hooks
- Loading branch information
1 parent
7821ea6
commit 5f5cd2c
Showing
11 changed files
with
329 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package keeper | ||
|
||
import ( | ||
"cosmossdk.io/store/prefix" | ||
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" | ||
cosmostypes "github.com/cometbft/cometbft/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
ethtypes "github.com/ethereum/go-ethereum/core/types" | ||
"github.com/evmos/ethermint/x/evm/tracing" | ||
"github.com/evmos/ethermint/x/evm/types" | ||
"math/big" | ||
) | ||
|
||
func BlocksBloom(k *Keeper, ctx sdk.Context) *big.Int { | ||
store := prefix.NewObjStore(ctx.ObjectStore(k.objectKey), types.KeyPrefixObjectBloom) | ||
it := store.Iterator(nil, nil) | ||
defer it.Close() | ||
|
||
bloom := new(big.Int) | ||
for ; it.Valid(); it.Next() { | ||
bloom.Or(bloom, it.Value().(*big.Int)) | ||
} | ||
return bloom | ||
} | ||
|
||
func ToCosmosStartBlockEvent(k *Keeper, ctx sdk.Context, coinbaseBytes []byte, blockHeader cmtproto.Header) tracing.CosmosStartBlockEvent { | ||
// ignore the errors as we are sure that the block header is valid | ||
h, _ := cosmostypes.HeaderFromProto(&blockHeader) | ||
h.ValidatorsHash = ctx.CometInfo().GetValidatorsHash() | ||
|
||
keeperParams := k.GetParams(ctx) | ||
ethCfg := keeperParams.ChainConfig.EthereumConfig(k.ChainID()) | ||
baseFee := k.GetBaseFee(ctx, ethCfg) | ||
gasLimit := uint64(ctx.ConsensusParams().Block.MaxGas) | ||
|
||
finalizedHeaderNumber := h.Height - 1 | ||
if h.Height == 0 { | ||
finalizedHeaderNumber = 0 | ||
} | ||
|
||
finalizedHeader := ðtypes.Header{ | ||
Number: big.NewInt(finalizedHeaderNumber), | ||
} | ||
|
||
return tracing.CosmosStartBlockEvent{ | ||
CosmosHeader: h, | ||
BaseFee: baseFee, | ||
GasLimit: gasLimit, | ||
Coinbase: coinbaseBytes, | ||
Finalized: finalizedHeader, | ||
} | ||
} | ||
|
||
func ToCosmosEndBlockEvent(k *Keeper, ctx sdk.Context) tracing.CosmosEndBlockEvent { | ||
return tracing.CosmosEndBlockEvent{ | ||
LogsBloom: BlocksBloom(k, ctx).Bytes(), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.