Skip to content

Commit

Permalink
istanbul: Log rebalance memo in engine.Finalize
Browse files Browse the repository at this point in the history
  • Loading branch information
blukat29 committed Jun 21, 2024
1 parent 64b875f commit db102c2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
5 changes: 1 addition & 4 deletions blockchain/system/rebalance.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func newRebalanceReceipt() *rebalanceResult {
}
}

func (result *rebalanceResult) memo(isKip103 bool) []byte {
func (result *rebalanceResult) Memo(isKip103 bool) []byte {
var (
memo []byte
err error
Expand Down Expand Up @@ -322,8 +322,5 @@ func RebalanceTreasury(state *state.StateDB, chain backends.BlockChainForCaller,
remainder := new(big.Int).Sub(totalZeroedAmount, totalAllocatedAmount)
result.Burnt.Add(result.Burnt, remainder)
result.Success = true

// Leave a memo for logging
logger.Info("successfully executed treasury rebalancing", "memo", string(result.memo(isKIP103)))
return result, nil
}
6 changes: 3 additions & 3 deletions blockchain/system/rebalance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func rebalanceTreasury(t *testing.T, sender *bind.TransactOpts, config *params.C
res, err := RebalanceTreasury(state, chain, chain.CurrentHeader())
if chain.Config().Kip103CompatibleBlock != nil && tc.expectBurnt.Cmp(big.NewInt(0)) == -1 {
assert.Equal(t, ErrRebalanceNotEnoughBalance, err)
t.Log(string(res.memo(true)))
t.Log(string(res.Memo(true)))
continue
}

Expand Down Expand Up @@ -250,9 +250,9 @@ func rebalanceTreasury(t *testing.T, sender *bind.TransactOpts, config *params.C
// assert.Equal(t, tc.expectKip103Memo, string(res.memo(isKip103)))
//}

t.Log(string(res.memo(isKip103)))
t.Log(string(res.Memo(isKip103)))
if !isKip103 {
assert.Equal(t, tc.expectKip160Memo, string(res.memo(isKip103)))
assert.Equal(t, tc.expectKip160Memo, string(res.Memo(isKip103)))
}
}
}
6 changes: 5 additions & 1 deletion consensus/istanbul/backend/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -553,9 +553,13 @@ func (sb *backend) Finalize(chain consensus.ChainReader, header *types.Header, s
// so the existing state db should be used to apply the rebalancing result.
// Only on the KIP-103 or KIP-160 hardfork block, the following logic should be executed
if chain.Config().IsKIP160ForkBlock(header.Number) || chain.Config().IsKIP103ForkBlock(header.Number) {
_, err := system.RebalanceTreasury(state, chain, header)
rebalanceResult, err := system.RebalanceTreasury(state, chain, header)
if err != nil {
logger.Error("failed to execute treasury rebalancing. State not changed", "err", err)
} else {
// Leave the memo in the log for later contract finalization
isKIP103 := chain.Config().IsKIP103ForkBlock(header.Number) // because memo format differs between KIP-103 and KIP-160
logger.Info("successfully executed treasury rebalancing", "memo", string(rebalanceResult.Memo(isKIP103)))
}
}

Expand Down

0 comments on commit db102c2

Please sign in to comment.