Skip to content

Commit 029774a

Browse files
author
seven
committed
fix debug api:Prevent mint for multiple transactions.Only the last transaction and the destination address of the transaction address is systemcontract.ValidatorContract will mint be generated
1 parent 5dc1b70 commit 029774a

File tree

6 files changed

+58
-2
lines changed

6 files changed

+58
-2
lines changed

consensus/consensus.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,6 @@ type PoSA interface {
145145
EnoughDistance(chain ChainReader, header *types.Header) bool
146146
IsLocalBlock(header *types.Header) bool
147147
AllowLightProcess(chain ChainReader, currentHeader *types.Header) bool
148+
149+
BlockRewards(blockNumber *big.Int) *big.Int
148150
}

consensus/parlia/parlia.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,6 +1052,15 @@ func (p *Parlia) getCurrentValidators(blockHash common.Hash) ([]common.Address,
10521052
}
10531053
return valz, nil
10541054
}
1055+
func (p *Parlia) BlockRewards(blockNumber *big.Int) *big.Int {
1056+
if rules := p.chainConfig.Rules(blockNumber); rules.HasBlockRewards {
1057+
blockRewards := p.chainConfig.Parlia.BlockRewards
1058+
if blockRewards != nil && blockRewards.Cmp(common.Big0) > 0 {
1059+
return blockRewards
1060+
}
1061+
}
1062+
return nil
1063+
}
10551064

10561065
// slash spoiled validators
10571066
func (p *Parlia) distributeIncoming(val common.Address, state *state.StateDB, header *types.Header, chain core.ChainContext,

eth/state_accessor.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"time"
2424

2525
"github.com/ethereum/go-ethereum/common"
26+
"github.com/ethereum/go-ethereum/common/systemcontract"
2627
"github.com/ethereum/go-ethereum/consensus"
2728
"github.com/ethereum/go-ethereum/core"
2829
"github.com/ethereum/go-ethereum/core/state"
@@ -201,6 +202,12 @@ func (eth *Ethereum) stateAtTransaction(block *types.Block, txIndex int, reexec
201202
statedb.SetBalance(consensus.SystemAddress, big.NewInt(0))
202203
statedb.AddBalance(context.Coinbase, balance)
203204
}
205+
if idx == len(block.Transactions())-1 && tx.To().Hex() == systemcontract.ValidatorContract {
206+
blockRewards := posa.BlockRewards(block.Header().Number)
207+
if blockRewards != nil {
208+
statedb.AddBalance(context.Coinbase, blockRewards)
209+
}
210+
}
204211
}
205212
statedb.Prepare(tx.Hash(), block.Hash(), idx)
206213
if _, err := core.ApplyMessage(vmenv, msg, new(core.GasPool).AddGas(tx.Gas())); err != nil {

eth/tracers/api.go

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"github.com/ethereum/go-ethereum/common"
3333
"github.com/ethereum/go-ethereum/common/gopool"
3434
"github.com/ethereum/go-ethereum/common/hexutil"
35+
"github.com/ethereum/go-ethereum/common/systemcontract"
3536
"github.com/ethereum/go-ethereum/consensus"
3637
"github.com/ethereum/go-ethereum/core"
3738
"github.com/ethereum/go-ethereum/core/rawdb"
@@ -281,6 +282,7 @@ func (api *API) traceChain(ctx context.Context, start, end *types.Block, config
281282
BlockHash: task.block.Hash(),
282283
TxIndex: i,
283284
TxHash: tx.Hash(),
285+
TxCount: len(task.block.Transactions()),
284286
}
285287
res, err := api.traceTx(localctx, msg, txctx, blockCtx, task.statedb, config)
286288
if err != nil {
@@ -540,7 +542,15 @@ func (api *API) IntermediateRoots(ctx context.Context, hash common.Hash, config
540542
statedb.SetBalance(consensus.SystemAddress, big.NewInt(0))
541543
statedb.AddBalance(vmctx.Coinbase, balance)
542544
}
545+
if i == len(block.Transactions())-1 && tx.To().Hex() == systemcontract.ValidatorContract {
546+
blockRewards := posa.BlockRewards(block.Header().Number)
547+
if blockRewards != nil {
548+
statedb.AddBalance(vmctx.Coinbase, blockRewards)
549+
}
550+
}
551+
543552
}
553+
544554
}
545555

546556
statedb.Prepare(tx.Hash(), block.Hash(), i)
@@ -621,6 +631,7 @@ func (api *API) traceBlock(ctx context.Context, block *types.Block, config *Trac
621631
BlockHash: blockHash,
622632
TxIndex: task.index,
623633
TxHash: txs[task.index].Hash(),
634+
TxCount: len(txs),
624635
}
625636
res, err := api.traceTx(ctx, msg, txctx, blockCtx, task.statedb, config)
626637
if err != nil {
@@ -640,14 +651,19 @@ func (api *API) traceBlock(ctx context.Context, block *types.Block, config *Trac
640651

641652
// Generate the next state snapshot fast without tracing
642653
msg, _ := tx.AsMessage(signer)
643-
644654
if posa, ok := api.backend.Engine().(consensus.PoSA); ok {
645655
if isSystem, _ := posa.IsSystemTransaction(tx, block.Header()); isSystem {
646656
balance := statedb.GetBalance(consensus.SystemAddress)
647657
if balance.Cmp(common.Big0) > 0 {
648658
statedb.SetBalance(consensus.SystemAddress, big.NewInt(0))
649659
statedb.AddBalance(block.Header().Coinbase, balance)
650660
}
661+
if i == len(txs)-1 && tx.To().Hex() == systemcontract.ValidatorContract {
662+
blockRewards := posa.BlockRewards(block.Header().Number)
663+
if blockRewards != nil {
664+
statedb.AddBalance(block.Header().Coinbase, blockRewards)
665+
}
666+
}
651667
}
652668
}
653669

@@ -772,6 +788,12 @@ func (api *API) standardTraceBlockToFile(ctx context.Context, block *types.Block
772788
statedb.SetBalance(consensus.SystemAddress, big.NewInt(0))
773789
statedb.AddBalance(vmctx.Coinbase, balance)
774790
}
791+
if i == len(block.Transactions())-1 && tx.To().Hex() == systemcontract.ValidatorContract {
792+
blockRewards := posa.BlockRewards(block.Header().Number)
793+
if blockRewards != nil {
794+
statedb.AddBalance(vmctx.Coinbase, blockRewards)
795+
}
796+
}
775797
}
776798
}
777799
statedb.Prepare(tx.Hash(), block.Hash(), i)
@@ -836,6 +858,7 @@ func (api *API) TraceTransaction(ctx context.Context, hash common.Hash, config *
836858
BlockHash: blockHash,
837859
TxIndex: int(index),
838860
TxHash: hash,
861+
TxCount: len(block.Transactions()),
839862
}
840863
return api.traceTx(ctx, msg, txctx, vmctx, statedb, config)
841864
}
@@ -938,6 +961,13 @@ func (api *API) traceTx(ctx context.Context, message core.Message, txctx *Contex
938961
statedb.SetBalance(consensus.SystemAddress, big.NewInt(0))
939962
statedb.AddBalance(vmctx.Coinbase, balance)
940963
}
964+
if txctx.TxIndex == txctx.TxCount-1 && message.To().Hex() == systemcontract.ValidatorContract {
965+
blockRewards := posa.BlockRewards(vmctx.BlockNumber)
966+
if blockRewards != nil {
967+
statedb.AddBalance(vmctx.Coinbase, blockRewards)
968+
}
969+
}
970+
941971
}
942972

943973
// Call Prepare to clear out the statedb access list

eth/tracers/tracers.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ type Context struct {
3131
BlockHash common.Hash // Hash of the block the tx is contained within (zero if dangling tx or call)
3232
TxIndex int // Index of the transaction within a block (zero if dangling tx or call)
3333
TxHash common.Hash // Hash of the transaction being traced (zero if dangling call)
34+
TxCount int
3435
}
3536

3637
// Tracer interface extends vm.EVMLogger and additionally

internal/ethapi/api.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import (
3636
"github.com/ethereum/go-ethereum/common/gopool"
3737
"github.com/ethereum/go-ethereum/common/hexutil"
3838
"github.com/ethereum/go-ethereum/common/math"
39+
"github.com/ethereum/go-ethereum/common/systemcontract"
3940
"github.com/ethereum/go-ethereum/consensus"
4041
"github.com/ethereum/go-ethereum/consensus/clique"
4142
"github.com/ethereum/go-ethereum/core"
@@ -1197,7 +1198,7 @@ func (s *PublicBlockChainAPI) replay(ctx context.Context, block *types.Block, ac
11971198

11981199
// Recompute transactions.
11991200
signer := types.MakeSigner(s.b.ChainConfig(), block.Number())
1200-
for _, tx := range block.Transactions() {
1201+
for i, tx := range block.Transactions() {
12011202
// Skip data empty tx and to is one of the interested accounts tx.
12021203
skip := false
12031204
if len(tx.Data()) == 0 {
@@ -1233,6 +1234,12 @@ func (s *PublicBlockChainAPI) replay(ctx context.Context, block *types.Block, ac
12331234
statedb.SetBalance(consensus.SystemAddress, big.NewInt(0))
12341235
statedb.AddBalance(block.Header().Coinbase, balance)
12351236
}
1237+
if i == len(block.Transactions())-1 && tx.To().Hex() == systemcontract.ValidatorContract {
1238+
blockRewards := posa.BlockRewards(block.Header().Number)
1239+
if blockRewards != nil {
1240+
statedb.AddBalance(context.Coinbase, blockRewards)
1241+
}
1242+
}
12361243
}
12371244
}
12381245

0 commit comments

Comments
 (0)