mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 02:42:27 +00:00
make SupplyInfo private
This commit is contained in:
parent
df69332109
commit
fb0160ba9f
2 changed files with 27 additions and 16 deletions
|
|
@ -36,13 +36,24 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/core/vm"
|
"github.com/ethereum/go-ethereum/core/vm"
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/eth/tracers"
|
"github.com/ethereum/go-ethereum/eth/tracers"
|
||||||
"github.com/ethereum/go-ethereum/eth/tracers/live"
|
|
||||||
"github.com/ethereum/go-ethereum/params"
|
"github.com/ethereum/go-ethereum/params"
|
||||||
|
|
||||||
// Force-load live packages, to trigger registration
|
// Force-load live packages, to trigger registration
|
||||||
_ "github.com/ethereum/go-ethereum/eth/tracers/live"
|
_ "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 emptyBlockGenerationFunc(b *core.BlockGen) {}
|
||||||
|
|
||||||
func TestSupplyGenesisAlloc(t *testing.T) {
|
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)),
|
Delta: new(big.Int).Mul(common.Big2, big.NewInt(params.Ether)),
|
||||||
Reward: common.Big0,
|
Reward: common.Big0,
|
||||||
Withdrawals: 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)),
|
Delta: new(big.Int).Mul(common.Big2, big.NewInt(params.Ether)),
|
||||||
Reward: new(big.Int).Mul(common.Big2, big.NewInt(params.Ether)),
|
Reward: new(big.Int).Mul(common.Big2, big.NewInt(params.Ether)),
|
||||||
Withdrawals: common.Big0,
|
Withdrawals: common.Big0,
|
||||||
|
|
@ -162,7 +173,7 @@ func TestSupplyEip1559Burn(t *testing.T) {
|
||||||
head = chain.CurrentBlock()
|
head = chain.CurrentBlock()
|
||||||
reward = new(big.Int).Mul(common.Big2, big.NewInt(params.Ether))
|
reward = new(big.Int).Mul(common.Big2, big.NewInt(params.Ether))
|
||||||
burn = new(big.Int).Mul(big.NewInt(21000), head.BaseFee)
|
burn = new(big.Int).Mul(big.NewInt(21000), head.BaseFee)
|
||||||
expected = live.SupplyInfo{
|
expected = supplyInfo{
|
||||||
Delta: new(big.Int).Sub(reward, burn),
|
Delta: new(big.Int).Sub(reward, burn),
|
||||||
Reward: reward,
|
Reward: reward,
|
||||||
Withdrawals: common.Big0,
|
Withdrawals: common.Big0,
|
||||||
|
|
@ -204,7 +215,7 @@ func TestSupplyWithdrawals(t *testing.T) {
|
||||||
|
|
||||||
var (
|
var (
|
||||||
head = chain.CurrentBlock()
|
head = chain.CurrentBlock()
|
||||||
expected = live.SupplyInfo{
|
expected = supplyInfo{
|
||||||
Delta: big.NewInt(1337000000000),
|
Delta: big.NewInt(1337000000000),
|
||||||
Reward: common.Big0,
|
Reward: common.Big0,
|
||||||
Withdrawals: big.NewInt(1337000000000),
|
Withdrawals: big.NewInt(1337000000000),
|
||||||
|
|
@ -302,7 +313,7 @@ func TestSupplySelfdestruct(t *testing.T) {
|
||||||
|
|
||||||
head := preCancunChain.CurrentBlock()
|
head := preCancunChain.CurrentBlock()
|
||||||
// Check live trace output
|
// Check live trace output
|
||||||
expected := live.SupplyInfo{
|
expected := supplyInfo{
|
||||||
Delta: big.NewInt(-55294500000000),
|
Delta: big.NewInt(-55294500000000),
|
||||||
Reward: common.Big0,
|
Reward: common.Big0,
|
||||||
Withdrawals: common.Big0,
|
Withdrawals: common.Big0,
|
||||||
|
|
@ -345,7 +356,7 @@ func TestSupplySelfdestruct(t *testing.T) {
|
||||||
|
|
||||||
// Check live trace output
|
// Check live trace output
|
||||||
head = postCancunChain.CurrentBlock()
|
head = postCancunChain.CurrentBlock()
|
||||||
expected = live.SupplyInfo{
|
expected = supplyInfo{
|
||||||
Delta: big.NewInt(-55289500000000),
|
Delta: big.NewInt(-55289500000000),
|
||||||
Reward: common.Big0,
|
Reward: common.Big0,
|
||||||
Withdrawals: 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())))
|
blockBurn := new(big.Int).Mul(block.BaseFee(), big.NewInt(int64(block.GasUsed())))
|
||||||
totalBurn := new(big.Int).Add(blockBurn, eth5) // 5ETH burned from contract B
|
totalBurn := new(big.Int).Add(blockBurn, eth5) // 5ETH burned from contract B
|
||||||
|
|
||||||
expected := live.SupplyInfo{
|
expected := supplyInfo{
|
||||||
Delta: new(big.Int).Neg(totalBurn),
|
Delta: new(big.Int).Neg(totalBurn),
|
||||||
Reward: common.Big0,
|
Reward: common.Big0,
|
||||||
Withdrawals: 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 (
|
var (
|
||||||
engine = beacon.New(ethash.NewFaker())
|
engine = beacon.New(ethash.NewFaker())
|
||||||
)
|
)
|
||||||
|
|
@ -549,13 +560,13 @@ func testSupplyTracer(t *testing.T, genesis *core.Genesis, gen func(*core.BlockG
|
||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
|
||||||
var output []live.SupplyInfo
|
var output []supplyInfo
|
||||||
scanner := bufio.NewScanner(file)
|
scanner := bufio.NewScanner(file)
|
||||||
|
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
blockBytes := scanner.Bytes()
|
blockBytes := scanner.Bytes()
|
||||||
|
|
||||||
var info live.SupplyInfo
|
var info supplyInfo
|
||||||
if err := json.Unmarshal(blockBytes, &info); err != nil {
|
if err := json.Unmarshal(blockBytes, &info); err != nil {
|
||||||
return nil, chain, fmt.Errorf("failed to unmarshal result: %v", err)
|
return nil, chain, fmt.Errorf("failed to unmarshal result: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ func init() {
|
||||||
tracers.LiveDirectory.Register("supply", newSupply)
|
tracers.LiveDirectory.Register("supply", newSupply)
|
||||||
}
|
}
|
||||||
|
|
||||||
type SupplyInfo struct {
|
type supplyInfo struct {
|
||||||
Delta *big.Int `json:"delta"`
|
Delta *big.Int `json:"delta"`
|
||||||
Reward *big.Int `json:"reward"`
|
Reward *big.Int `json:"reward"`
|
||||||
Withdrawals *big.Int `json:"withdrawals"`
|
Withdrawals *big.Int `json:"withdrawals"`
|
||||||
|
|
@ -33,7 +33,7 @@ type SupplyInfo struct {
|
||||||
ParentHash common.Hash `json:"parentHash"`
|
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.Burn.Add(s.Burn, amount)
|
||||||
s.Delta.Sub(s.Delta, amount)
|
s.Delta.Sub(s.Delta, amount)
|
||||||
}
|
}
|
||||||
|
|
@ -43,8 +43,8 @@ type supplyTxCallstack struct {
|
||||||
burn *big.Int
|
burn *big.Int
|
||||||
}
|
}
|
||||||
|
|
||||||
delta SupplyInfo
|
|
||||||
type supply struct {
|
type supply struct {
|
||||||
|
delta supplyInfo
|
||||||
txCallstack []supplyTxCallstack // Callstack for current transaction
|
txCallstack []supplyTxCallstack // Callstack for current transaction
|
||||||
logger *log.Logger
|
logger *log.Logger
|
||||||
}
|
}
|
||||||
|
|
@ -94,8 +94,8 @@ func newSupply(cfg json.RawMessage) (*tracing.Hooks, error) {
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func newSupplyInfo() SupplyInfo {
|
func newSupplyInfo() supplyInfo {
|
||||||
return SupplyInfo{
|
return supplyInfo{
|
||||||
Delta: big.NewInt(0),
|
Delta: big.NewInt(0),
|
||||||
Reward: big.NewInt(0),
|
Reward: big.NewInt(0),
|
||||||
Withdrawals: big.NewInt(0),
|
Withdrawals: big.NewInt(0),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue