Skip to content

Commit 27ad53c

Browse files
authored
chore: add query to fetch highest voted height (#100)
## Description Adds new storage and query needed by finality-provider [here](https://github.com/babylonlabs-io/finality-provider/blob/421649a9f9c4dbf837eddb05f96249df68adb67e/bsn/rollup/clientcontroller/consumer.go#L537) <!-- Brief description of changes --> ## Checklist - [ ] I have updated the [docs/SPEC.md](https://github.com/babylonlabs-io/rollup-bsn-contracts/blob/main/docs/SPEC.md) file if this change affects the specification - [x] I have updated the schema by running `cargo gen-schema`
1 parent d386d6e commit 27ad53c

File tree

10 files changed

+532
-28
lines changed

10 files changed

+532
-28
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
4343
bsn_activation_height and finality_signature_interval for spam protection
4444
* [97](https://github.com/babylonlabs-io/rollup-bsn-contracts/pull/97) feat:
4545
versioning of FP allowlist
46+
* [100](https://github.com/babylonlabs-io/rollup-bsn-contracts/pull/100) chore:
47+
add query to fetch highest voted height
4648

4749
### Improvements
4850

contracts/finality/schema/finality.json

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,67 @@
325325
}
326326
},
327327
"additionalProperties": false
328+
},
329+
{
330+
"description": "Update contract configuration.\n\nThis message can be called by the admin only. All fields are optional - only provided fields will be updated. Updated values must pass the same validation as during instantiation.",
331+
"type": "object",
332+
"required": [
333+
"update_config"
334+
],
335+
"properties": {
336+
"update_config": {
337+
"type": "object",
338+
"properties": {
339+
"bsn_activation_height": {
340+
"description": "New BSN activation height (if provided)",
341+
"type": [
342+
"integer",
343+
"null"
344+
],
345+
"format": "uint64",
346+
"minimum": 0.0
347+
},
348+
"finality_signature_interval": {
349+
"description": "New finality signature interval (if provided)",
350+
"type": [
351+
"integer",
352+
"null"
353+
],
354+
"format": "uint64",
355+
"minimum": 0.0
356+
},
357+
"max_msgs_per_interval": {
358+
"description": "New maximum messages per finality provider per interval (if provided)",
359+
"type": [
360+
"integer",
361+
"null"
362+
],
363+
"format": "uint32",
364+
"minimum": 0.0
365+
},
366+
"min_pub_rand": {
367+
"description": "New minimum number of public randomness values required (if provided)",
368+
"type": [
369+
"integer",
370+
"null"
371+
],
372+
"format": "uint64",
373+
"minimum": 0.0
374+
},
375+
"rate_limiting_interval": {
376+
"description": "New rate limiting interval in blocks (if provided)",
377+
"type": [
378+
"integer",
379+
"null"
380+
],
381+
"format": "uint64",
382+
"minimum": 0.0
383+
}
384+
},
385+
"additionalProperties": false
386+
}
387+
},
388+
"additionalProperties": false
328389
}
329390
],
330391
"definitions": {
@@ -485,6 +546,28 @@
485546
},
486547
"additionalProperties": false
487548
},
549+
{
550+
"description": "`HighestVotedHeight` returns the highest rollup block height that the given finality provider has voted on.\n\n`btc_pk_hex` is the BTC public key of the finality provider, in hex format. Returns None if the finality provider has never submitted a finality signature.",
551+
"type": "object",
552+
"required": [
553+
"highest_voted_height"
554+
],
555+
"properties": {
556+
"highest_voted_height": {
557+
"type": "object",
558+
"required": [
559+
"btc_pk_hex"
560+
],
561+
"properties": {
562+
"btc_pk_hex": {
563+
"type": "string"
564+
}
565+
},
566+
"additionalProperties": false
567+
}
568+
},
569+
"additionalProperties": false
570+
},
488571
{
489572
"type": "object",
490573
"required": [
@@ -780,6 +863,16 @@
780863
}
781864
}
782865
},
866+
"highest_voted_height": {
867+
"$schema": "http://json-schema.org/draft-07/schema#",
868+
"title": "Nullable_uint64",
869+
"type": [
870+
"integer",
871+
"null"
872+
],
873+
"format": "uint64",
874+
"minimum": 0.0
875+
},
783876
"last_pub_rand_commit": {
784877
"$schema": "http://json-schema.org/draft-07/schema#",
785878
"title": "Nullable_PubRandCommit",

contracts/finality/schema/raw/execute.json

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,67 @@
255255
}
256256
},
257257
"additionalProperties": false
258+
},
259+
{
260+
"description": "Update contract configuration.\n\nThis message can be called by the admin only. All fields are optional - only provided fields will be updated. Updated values must pass the same validation as during instantiation.",
261+
"type": "object",
262+
"required": [
263+
"update_config"
264+
],
265+
"properties": {
266+
"update_config": {
267+
"type": "object",
268+
"properties": {
269+
"bsn_activation_height": {
270+
"description": "New BSN activation height (if provided)",
271+
"type": [
272+
"integer",
273+
"null"
274+
],
275+
"format": "uint64",
276+
"minimum": 0.0
277+
},
278+
"finality_signature_interval": {
279+
"description": "New finality signature interval (if provided)",
280+
"type": [
281+
"integer",
282+
"null"
283+
],
284+
"format": "uint64",
285+
"minimum": 0.0
286+
},
287+
"max_msgs_per_interval": {
288+
"description": "New maximum messages per finality provider per interval (if provided)",
289+
"type": [
290+
"integer",
291+
"null"
292+
],
293+
"format": "uint32",
294+
"minimum": 0.0
295+
},
296+
"min_pub_rand": {
297+
"description": "New minimum number of public randomness values required (if provided)",
298+
"type": [
299+
"integer",
300+
"null"
301+
],
302+
"format": "uint64",
303+
"minimum": 0.0
304+
},
305+
"rate_limiting_interval": {
306+
"description": "New rate limiting interval in blocks (if provided)",
307+
"type": [
308+
"integer",
309+
"null"
310+
],
311+
"format": "uint64",
312+
"minimum": 0.0
313+
}
314+
},
315+
"additionalProperties": false
316+
}
317+
},
318+
"additionalProperties": false
258319
}
259320
],
260321
"definitions": {

contracts/finality/schema/raw/query.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,28 @@
117117
},
118118
"additionalProperties": false
119119
},
120+
{
121+
"description": "`HighestVotedHeight` returns the highest rollup block height that the given finality provider has voted on.\n\n`btc_pk_hex` is the BTC public key of the finality provider, in hex format. Returns None if the finality provider has never submitted a finality signature.",
122+
"type": "object",
123+
"required": [
124+
"highest_voted_height"
125+
],
126+
"properties": {
127+
"highest_voted_height": {
128+
"type": "object",
129+
"required": [
130+
"btc_pk_hex"
131+
],
132+
"properties": {
133+
"btc_pk_hex": {
134+
"type": "string"
135+
}
136+
},
137+
"additionalProperties": false
138+
}
139+
},
140+
"additionalProperties": false
141+
},
120142
{
121143
"type": "object",
122144
"required": [
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"title": "Nullable_uint64",
4+
"type": [
5+
"integer",
6+
"null"
7+
],
8+
"format": "uint64",
9+
"minimum": 0.0
10+
}

contracts/finality/src/contract.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use crate::state::allowlist::{
1414
get_allowed_finality_providers, get_allowed_finality_providers_at_height,
1515
};
1616
use crate::state::config::{get_config, set_config, Config, RateLimitingConfig, ADMIN};
17+
use crate::state::finality::get_highest_voted_height;
1718
use crate::state::pruning::handle_prune_data;
1819
use crate::state::public_randomness::{
1920
get_first_pub_rand_commit, get_last_pub_rand_commit, list_pub_rand_commit,
@@ -99,6 +100,9 @@ pub fn query(
99100
limit,
100101
reverse,
101102
)?)?),
103+
QueryMsg::HighestVotedHeight { btc_pk_hex } => Ok(to_json_binary(
104+
&get_highest_voted_height(deps.storage, &hex::decode(&btc_pk_hex)?)?,
105+
)?),
102106
QueryMsg::AllowedFinalityProviders {} => Ok(to_json_binary(
103107
&get_allowed_finality_providers(deps.storage)?,
104108
)?),

contracts/finality/src/error.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ use babylon_merkle::error::MerkleError;
1111
pub enum ContractError {
1212
#[error("Failed to load finality signature: {0} at height {1}")]
1313
FailedToLoadFinalitySignature(String, u64),
14+
#[error("Failed to load highest voted height for finality provider: {0}")]
15+
FailedToLoadHighestVotedHeight(String),
16+
#[error("Failed to save highest voted height for finality provider: {0}")]
17+
FailedToSaveHighestVotedHeight(String),
1418
#[error("Failed to load signatories by block hash: {0} at height {1}")]
1519
FailedToLoadSignatories(String, u64),
1620
#[error("Empty signature from the delegator")]

contracts/finality/src/msg.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ pub enum QueryMsg {
8585
limit: Option<u32>,
8686
reverse: Option<bool>,
8787
},
88+
/// `HighestVotedHeight` returns the highest rollup block height that the given finality provider has voted on.
89+
///
90+
/// `btc_pk_hex` is the BTC public key of the finality provider, in hex format.
91+
/// Returns None if the finality provider has never submitted a finality signature.
92+
#[returns(Option<u64>)]
93+
HighestVotedHeight { btc_pk_hex: String },
8894

8995
// SHOULD: Administrative queries
9096
#[returns(AdminResponse)]

0 commit comments

Comments
 (0)