-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cluster: draft v1.6 lock with deposit data (#1813)
Adds a new draft lock version v1.6 which includes deposit data in the lock's distributed validators. category: feature ticket: #1775
- Loading branch information
1 parent
d56cfd5
commit 14d6b7c
Showing
18 changed files
with
465 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright © 2022 Obol Labs Inc. | ||
// | ||
// This program is free software: you can redistribute it and/or modify it | ||
// under the terms of the GNU General Public License as published by the Free | ||
// Software Foundation, either version 3 of the License, or (at your option) | ||
// any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, but WITHOUT | ||
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
// more details. | ||
// | ||
// You should have received a copy of the GNU General Public License along with | ||
// this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
package cluster | ||
|
||
// DepositData defines the deposit data to activate a validator. | ||
// https://github.com/ethereum/consensus-specs/blob/dev/specs/phase0/beacon-chain.md#depositdata | ||
type DepositData struct { | ||
// PubKey is the validator public key. | ||
PubKey []byte `json:"pubkey" ssz:"Bytes48" lock_hash:"0"` | ||
|
||
// WithdrawalCredentials included in the deposit. | ||
WithdrawalCredentials []byte `json:"withdrawal_credentials" ssz:"Bytes32" lock_hash:"1"` | ||
|
||
// Amount is the amount in Gwei to be deposited. | ||
Amount int `json:"amount" ssz:"uint64" lock_hash:"2"` | ||
|
||
// Signature is the BLS signature of the deposit message (above three fields). | ||
Signature []byte `json:"signature" ssz:"Bytes96" lock_hash:"3"` | ||
} | ||
|
||
// depositDataJSON is the json formatter of DepositData. | ||
type depositDataJSON struct { | ||
PubKey ethHex `json:"pubkey"` | ||
WithdrawalCredentials ethHex `json:"withdrawal_credentials"` | ||
Amount int `json:"amount,string"` | ||
Signature ethHex `json:"signature"` | ||
} | ||
|
||
// depositDataToJSON converts DepositData to depositDataJSON. | ||
func depositDataToJSON(d DepositData) depositDataJSON { | ||
return depositDataJSON{ | ||
PubKey: d.PubKey, | ||
WithdrawalCredentials: d.WithdrawalCredentials, | ||
Amount: d.Amount, | ||
Signature: d.Signature, | ||
} | ||
} | ||
|
||
// depositDataFromJSON converts depositDataJSON to DepositData. | ||
func depositDataFromJSON(d depositDataJSON) DepositData { | ||
return DepositData{ | ||
PubKey: d.PubKey, | ||
WithdrawalCredentials: d.WithdrawalCredentials, | ||
Amount: d.Amount, | ||
Signature: d.Signature, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright © 2022 Obol Labs Inc. | ||
// | ||
// This program is free software: you can redistribute it and/or modify it | ||
// under the terms of the GNU General Public License as published by the Free | ||
// Software Foundation, either version 3 of the License, or (at your option) | ||
// any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, but WITHOUT | ||
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
// more details. | ||
// | ||
// You should have received a copy of the GNU General Public License along with | ||
// this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
package cluster | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
|
||
eth2p0 "github.com/attestantio/go-eth2-client/spec/phase0" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestDepositJSON(t *testing.T) { | ||
deposit := RandomDepositData() | ||
depositJSON := depositDataToJSON(deposit) | ||
|
||
eth2Deposit := ð2p0.DepositData{ | ||
PublicKey: *(*eth2p0.BLSPubKey)(deposit.PubKey), | ||
WithdrawalCredentials: deposit.WithdrawalCredentials, | ||
Amount: eth2p0.Gwei(deposit.Amount), | ||
Signature: *(*eth2p0.BLSSignature)(deposit.Signature), | ||
} | ||
|
||
b1, err := json.MarshalIndent(depositJSON, "", " ") | ||
require.NoError(t, err) | ||
b2, err := json.MarshalIndent(eth2Deposit, "", " ") | ||
require.NoError(t, err) | ||
|
||
require.Equal(t, b1, b2) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.