Skip to content

Commit

Permalink
testutil: fix miner fees race in MineBlock
Browse files Browse the repository at this point in the history
  • Loading branch information
peterjan committed Apr 17, 2024
1 parent c7958e8 commit a364bd6
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions testutil/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,19 @@ func Network() (*consensus.Network, types.Block) {
// MineBlock mines a block with the given transactions, transaction fees are
// added to the miner payout.
func MineBlock(cm *chain.Manager, minerAddress types.Address) types.Block {
var minerFees types.Currency
for _, txn := range cm.PoolTransactions() {
minerFees = minerFees.Add(txn.TotalFees())
}

state := cm.TipState()
b := types.Block{
ParentID: state.Index.ID,
Timestamp: types.CurrentTimestamp(),
Transactions: cm.PoolTransactions(),
MinerPayouts: []types.SiacoinOutput{{Address: minerAddress, Value: state.BlockReward().Add(minerFees)}},
MinerPayouts: []types.SiacoinOutput{{Address: minerAddress, Value: state.BlockReward()}},
}

// add miner fees to payout
for _, txn := range b.Transactions {
b.MinerPayouts[0].Value = b.MinerPayouts[0].Value.Add(txn.TotalFees())
}

if !coreutils.FindBlockNonce(state, &b, 5*time.Second) {
panic("failed to find nonce")
}
Expand Down

0 comments on commit a364bd6

Please sign in to comment.