feat(node-api): Create proof endpoint for validator balance#2840
feat(node-api): Create proof endpoint for validator balance#2840
Conversation
Co-authored-by: calbera <calbera@berachain.com>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #2840 +/- ##
==========================================
- Coverage 60.64% 60.53% -0.11%
==========================================
Files 354 356 +2
Lines 16673 16824 +151
==========================================
+ Hits 10111 10185 +74
- Misses 5773 5841 +68
- Partials 789 798 +9
🚀 New features to boost your workflow:
|
| bs := mock.NewBeaconStateWith( | ||
| tc.slot, vals, 0, common.ExecutionAddress{}, tc.forkVersion, | ||
| ) | ||
|
|
||
| bs.Balances = make([]uint64, tc.numValidators) | ||
| bs.Balances[tc.valIndex] = tc.balance | ||
|
|
||
| bbh := ctypes.NewBeaconBlockHeader( | ||
| tc.slot, | ||
| tc.valIndex, | ||
| tc.parentBlockRoot, | ||
| bs.HashTreeRoot(), | ||
| tc.bodyRoot, | ||
| ) | ||
|
|
||
| proof, _, _, err := merkle.ProveBalanceInBlock(tc.valIndex, bbh, bs, bs.Balances) | ||
| require.NoError(t, err) | ||
| expectedProof := ReadProofFromFile(t, tc.expectedProofFile) |
There was a problem hiding this comment.
@bearmigiano you can use this code to re-create the balance proofs for specific data as needed in contracts testing
|
|
||
| // BalanceLeaf is the leaf containing the validator's balance along with up | ||
| // to 3 other validators' balances (packed 4 per leaf). | ||
| BalanceLeaf common.Root `json:"balance_leaf"` |
There was a problem hiding this comment.
@bearmigiano important to note for staking pools: The leaf of the proof is not just the HashTreeRoot of the balance. Since the leaf contains multiple balances (not just the one we are proving), you must use this one while verifying the proof.
Signed-off-by: Cal Bera <calbera@berachain.com>
Signed-off-by: Cal Bera <calbera@berachain.com>
| type ValidatorBalanceRequest struct { | ||
| types.TimestampIDRequest | ||
| ValidatorIndex string `param:"validator_index" validate:"required,numeric"` | ||
| } |
There was a problem hiding this comment.
This seems identical to ValidatorCredentialsRequest. Can we use a type alias instead of duplicating the requests?
…eate-node-api-endpoint-for-validator-balance-d97e
Add a node-api endpoint to provide Merkle proofs for a validator's balance at a specific timestamp.