make SupplyInfo private

This commit is contained in:
Chris Ziogas 2024-03-28 20:03:33 +02:00
parent df69332109
commit fb0160ba9f
No known key found for this signature in database
GPG key ID: 2329CF479E36E2DA
2 changed files with 27 additions and 16 deletions

View file

@ -36,13 +36,24 @@ import (
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/eth/tracers"
"github.com/ethereum/go-ethereum/eth/tracers/live"
"github.com/ethereum/go-ethereum/params"
// Force-load live packages, to trigger registration
_ "github.com/ethereum/go-ethereum/eth/tracers/live"
)
type supplyInfo struct {
Delta *big.Int `json:"delta"`
Reward *big.Int `json:"reward"`
Withdrawals *big.Int `json:"withdrawals"`
Burn *big.Int `json:"burn"`
// Block info
Number uint64 `json:"blockNumber"`
Hash common.Hash `json:"hash"`
ParentHash common.Hash `json:"parentHash"`
}
func emptyBlockGenerationFunc(b *core.BlockGen) {}
func TestSupplyGenesisAlloc(t *testing.T) {
@ -64,7 +75,7 @@ func TestSupplyGenesisAlloc(t *testing.T) {
}
)
expected := live.SupplyInfo{
expected := supplyInfo{
Delta: new(big.Int).Mul(common.Big2, big.NewInt(params.Ether)),
Reward: common.Big0,
Withdrawals: common.Big0,
@ -95,7 +106,7 @@ func TestSupplyRewards(t *testing.T) {
}
)
expected := live.SupplyInfo{
expected := supplyInfo{
Delta: new(big.Int).Mul(common.Big2, big.NewInt(params.Ether)),
Reward: new(big.Int).Mul(common.Big2, big.NewInt(params.Ether)),
Withdrawals: common.Big0,
@ -162,7 +173,7 @@ func TestSupplyEip1559Burn(t *testing.T) {
head = chain.CurrentBlock()
reward = new(big.Int).Mul(common.Big2, big.NewInt(params.Ether))
burn = new(big.Int).Mul(big.NewInt(21000), head.BaseFee)
expected = live.SupplyInfo{
expected = supplyInfo{
Delta: new(big.Int).Sub(reward, burn),
Reward: reward,
Withdrawals: common.Big0,
@ -204,7 +215,7 @@ func TestSupplyWithdrawals(t *testing.T) {
var (
head = chain.CurrentBlock()
expected = live.SupplyInfo{
expected = supplyInfo{
Delta: big.NewInt(1337000000000),
Reward: common.Big0,
Withdrawals: big.NewInt(1337000000000),
@ -302,7 +313,7 @@ func TestSupplySelfdestruct(t *testing.T) {
head := preCancunChain.CurrentBlock()
// Check live trace output
expected := live.SupplyInfo{
expected := supplyInfo{
Delta: big.NewInt(-55294500000000),
Reward: common.Big0,
Withdrawals: common.Big0,
@ -345,7 +356,7 @@ func TestSupplySelfdestruct(t *testing.T) {
// Check live trace output
head = postCancunChain.CurrentBlock()
expected = live.SupplyInfo{
expected = supplyInfo{
Delta: big.NewInt(-55289500000000),
Reward: common.Big0,
Withdrawals: common.Big0,
@ -495,7 +506,7 @@ func TestSupplySelfdestructItselfAndRevert(t *testing.T) {
blockBurn := new(big.Int).Mul(block.BaseFee(), big.NewInt(int64(block.GasUsed())))
totalBurn := new(big.Int).Add(blockBurn, eth5) // 5ETH burned from contract B
expected := live.SupplyInfo{
expected := supplyInfo{
Delta: new(big.Int).Neg(totalBurn),
Reward: common.Big0,
Withdrawals: common.Big0,
@ -512,7 +523,7 @@ func TestSupplySelfdestructItselfAndRevert(t *testing.T) {
}
}
func testSupplyTracer(t *testing.T, genesis *core.Genesis, gen func(*core.BlockGen)) ([]live.SupplyInfo, *core.BlockChain, error) {
func testSupplyTracer(t *testing.T, genesis *core.Genesis, gen func(*core.BlockGen)) ([]supplyInfo, *core.BlockChain, error) {
var (
engine = beacon.New(ethash.NewFaker())
)
@ -549,13 +560,13 @@ func testSupplyTracer(t *testing.T, genesis *core.Genesis, gen func(*core.BlockG
}
defer file.Close()
var output []live.SupplyInfo
var output []supplyInfo
scanner := bufio.NewScanner(file)
for scanner.Scan() {
blockBytes := scanner.Bytes()
var info live.SupplyInfo
var info supplyInfo
if err := json.Unmarshal(blockBytes, &info); err != nil {
return nil, chain, fmt.Errorf("failed to unmarshal result: %v", err)
}

View file

@ -21,7 +21,7 @@ func init() {
tracers.LiveDirectory.Register("supply", newSupply)
}
type SupplyInfo struct {
type supplyInfo struct {
Delta *big.Int `json:"delta"`
Reward *big.Int `json:"reward"`
Withdrawals *big.Int `json:"withdrawals"`
@ -33,7 +33,7 @@ type SupplyInfo struct {
ParentHash common.Hash `json:"parentHash"`
}
func (s *SupplyInfo) burn(amount *big.Int) {
func (s *supplyInfo) burn(amount *big.Int) {
s.Burn.Add(s.Burn, amount)
s.Delta.Sub(s.Delta, amount)
}
@ -43,8 +43,8 @@ type supplyTxCallstack struct {
burn *big.Int
}
delta SupplyInfo
type supply struct {
delta supplyInfo
txCallstack []supplyTxCallstack // Callstack for current transaction
logger *log.Logger
}
@ -94,8 +94,8 @@ func newSupply(cfg json.RawMessage) (*tracing.Hooks, error) {
}, nil
}
func newSupplyInfo() SupplyInfo {
return SupplyInfo{
func newSupplyInfo() supplyInfo {
return supplyInfo{
Delta: big.NewInt(0),
Reward: big.NewInt(0),
Withdrawals: big.NewInt(0),