Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
32 changes: 31 additions & 1 deletion consensus/aura/aura.go
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ func (c *AuRa) Finalize(config *chain.Config, header *types.Header, state *state
}
if pendingTransitionProof != nil {
if header.Number.Uint64() >= DEBUG_LOG_FROM {
fmt.Printf("insert_pending_trancition: %d,receipts=%d, lenProof=%d\n", header.Number.Uint64(), len(receipts), len(pendingTransitionProof))
fmt.Printf("insert_pending_transition: %d,receipts=%d, lenProof=%d\n", header.Number.Uint64(), len(receipts), len(pendingTransitionProof))
}
if err = e.PutPendingEpoch(header.Hash(), header.Number.Uint64(), pendingTransitionProof); err != nil {
return nil, nil, err
Expand Down Expand Up @@ -1407,6 +1407,36 @@ func registrarAbi() abi.ABI {
return a
}

func withdrawalAbi() abi.ABI {
a, err := abi.JSON(bytes.NewReader(contracts.Withdrawal))
if err != nil {
panic(err)
}
return a
}

// See https://github.com/gnosischain/specs/blob/master/execution/withdrawals.md
func (c *AuRa) ExecuteSystemWithdrawals(withdrawals []*types.Withdrawal, syscall consensus.SystemCall) error {
if c.cfg.WithdrawalContractAddress == nil {
return nil
}

amounts := make([]uint64, 0, len(withdrawals))
addresses := make([]libcommon.Address, 0, len(withdrawals))
for _, w := range withdrawals {
amounts = append(amounts, w.Amount)
addresses = append(addresses, w.Address)
}

packed, err := withdrawalAbi().Pack("executeSystemWithdrawals", amounts, addresses)
if err != nil {
return err
}

_, err = syscall(*c.cfg.WithdrawalContractAddress, packed)
return err
}

func getCertifier(registrar libcommon.Address, syscall consensus.SystemCall) *libcommon.Address {
hashedKey, err := common.HashData([]byte("service_transaction_checker"))
if err != nil {
Expand Down
7 changes: 7 additions & 0 deletions consensus/aura/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ type JsonSpec struct {
// This contract is primarily required to store the address of the Certifier contract.
Registrar *libcommon.Address `json:"registrar"`

// See https://github.com/gnosischain/specs/blob/master/execution/withdrawals.md
WithdrawalContractAddress *libcommon.Address `json:"withdrawalContractAddress"`

RewriteBytecode map[uint64]map[libcommon.Address]hexutil.Bytes `json:"rewriteBytecode"`
}

Expand Down Expand Up @@ -197,6 +200,9 @@ type AuthorityRoundParams struct {
// This contract is primarily required to store the address of the Certifier contract.
Registrar *libcommon.Address

// See https://github.com/gnosischain/specs/blob/master/execution/withdrawals.md
WithdrawalContractAddress *libcommon.Address

RewriteBytecode map[uint64]map[libcommon.Address][]byte
}

Expand All @@ -208,6 +214,7 @@ func FromJson(jsonParams JsonSpec) (AuthorityRoundParams, error) {
BlockGasLimitContractTransitions: jsonParams.BlockGasLimitContractTransitions,
PosdaoTransition: jsonParams.PosdaoTransition,
Registrar: jsonParams.Registrar,
WithdrawalContractAddress: jsonParams.WithdrawalContractAddress,
}
params.StepDurations = map[uint64]uint64{}
if jsonParams.StepDuration != nil {
Expand Down
3 changes: 3 additions & 0 deletions consensus/aura/contracts/embed.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ var Certifier []byte

//go:embed registrar.json
var Registrar []byte

//go:embed withdrawal.json
var Withdrawal []byte
19 changes: 19 additions & 0 deletions consensus/aura/contracts/withdrawal.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[
{
"constant": false,
"inputs": [
{
"name": "amounts",
"type": "uint64[]"
},
{
"name": "addresses",
"type": "address[]"
}
],
"name": "executeSystemWithdrawals",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
]
12 changes: 8 additions & 4 deletions consensus/serenity/serenity.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,14 @@ func (s *Serenity) Finalize(config *chain.Config, header *types.Header, state *s
if err := auraEngine.ApplyRewards(header, state, syscall); err != nil {
return nil, nil, err
}
}
for _, w := range withdrawals {
amountInWei := new(uint256.Int).Mul(uint256.NewInt(w.Amount), uint256.NewInt(params.GWei))
state.AddBalance(w.Address, amountInWei)
if err := auraEngine.ExecuteSystemWithdrawals(withdrawals, syscall); err != nil {
return nil, nil, err
}
} else {
for _, w := range withdrawals {
amountInWei := new(uint256.Int).Mul(uint256.NewInt(w.Amount), uint256.NewInt(params.GWei))
state.AddBalance(w.Address, amountInWei)
}
}
return txs, r, nil
}
Expand Down