Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tidy RebalanceTreasury and SimulatedBackend #21

Merged
merged 3 commits into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions blockchain/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,3 @@ func (st *StateTransition) refundGas(refundQuotient uint64) {
func (st *StateTransition) gasUsed() uint64 {
return st.initialGas - st.gas
}

func getBurnAmountMagma(fee *big.Int) *big.Int {
return new(big.Int).Div(fee, big.NewInt(2))
}
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
Loading