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

feat: gas limit fields #30

Merged
merged 1 commit into from
Nov 27, 2024
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
50 changes: 30 additions & 20 deletions crates/common/src/msgs/data_requests/dr_id.test_vector.json
Original file line number Diff line number Diff line change
@@ -1,151 +1,161 @@
[
{
"request_id": "2e469f40cf0afb5b93641c75aaecb654f0c73fc2dd4fcc350150c4825d2fb36e",
"request_id": "341f8933b3a10b929865d71d2f575794e0fbbafb7801b87975ebc7df20523e79",
"args": {
"version": "0.0.1",
"exec_program_id": "0000000000000000000000000000000000000000000000000000000000000000",
"exec_inputs": "",
"exec_gas_limit": 1000000,
"tally_program_id": "0000000000000000000000000000000000000000000000000000000000000000",
"tally_inputs": "",
"tally_gas_limit": 1000000,
"replication_factor": 1,
"consensus_filter": "AA==",
"gas_price": "0",
"gas_limit": 1000000,
"memo": "AA=="
}
},
{
"request_id": "a779f7061360e9fd128acb8686c393294db943848dc6c1e2248dd91fc79f3835",
"request_id": "71d862d090d5b0cfc0e38c553c42efff3f4f1fe17440104df2a6ed228eb1e4b2",
"args": {
"version": "0.0.1",
"exec_program_id": "0000000000000000000000000000000000000000000000000000000000000000",
"exec_inputs": "",
"exec_gas_limit": 1000000,
"tally_program_id": "0000000000000000000000000000000000000000000000000000000000000000",
"tally_inputs": "",
"tally_gas_limit": 1000000,
"replication_factor": 1,
"consensus_filter": "AA==",
"gas_price": "0",
"gas_limit": 1000000,
"memo": "AQ=="
}
},
{
"request_id": "cedae320cef23e6b50baf01f722b53818fd1d738d796a57a785c71436237dd35",
"request_id": "c320b7f89d04f6911165f36ae7d3b87a34e8fb6b41f7fc7dedeb49dcadda4e18",
"args": {
"version": "0.0.1",
"exec_program_id": "0000000000000000000000000000000000000000000000000000000000000000",
"exec_inputs": "",
"exec_gas_limit": 1000000,
"tally_program_id": "0000000000000000000000000000000000000000000000000000000000000000",
"tally_inputs": "",
"tally_gas_limit": 1000000,
"replication_factor": 1,
"consensus_filter": "AA==",
"gas_price": "0",
"gas_limit": 1000000,
"memo": "Ag=="
}
},
{
"request_id": "d2e85a4f932ee01d3aec08c4fb0725425073914e11e32219a90d0fb190adcce3",
"request_id": "fdbe500a36237c6d41a8d1d75c901f8f308ba460b7635ec649eae820e70818f1",
"args": {
"version": "0.0.1",
"exec_program_id": "0000000000000000000000000000000000000000000000000000000000000000",
"exec_inputs": "",
"exec_gas_limit": 1000000,
"tally_program_id": "0000000000000000000000000000000000000000000000000000000000000000",
"tally_inputs": "",
"tally_gas_limit": 1000000,
"replication_factor": 1,
"consensus_filter": "AA==",
"gas_price": "0",
"gas_limit": 1000000,
"memo": "Aw=="
}
},
{
"request_id": "a11695dd090839580ee64a21412e8f0843255c149f5352311ab6960990e690be",
"request_id": "5e9dc95872266e95a668f2cd82eb5316076f4c6828f824f5662673598838f8cf",
"args": {
"version": "0.0.1",
"exec_program_id": "0000000000000000000000000000000000000000000000000000000000000000",
"exec_inputs": "",
"exec_gas_limit": 1000000,
"tally_program_id": "0000000000000000000000000000000000000000000000000000000000000000",
"tally_inputs": "",
"tally_gas_limit": 1000000,
"replication_factor": 1,
"consensus_filter": "AA==",
"gas_price": "0",
"gas_limit": 1000000,
"memo": "BA=="
}
},
{
"request_id": "a4a1baa9d463128792770c0aadfc7916362d9309e19d709729060a48eb3b4b13",
"request_id": "ff7ec2a6f8d2c300cfb9643a9d5733069716671906a0088a05feea3ffa878cd9",
"args": {
"version": "0.0.1",
"exec_program_id": "0000000000000000000000000000000000000000000000000000000000000000",
"exec_inputs": "",
"exec_gas_limit": 1000000,
"tally_program_id": "0000000000000000000000000000000000000000000000000000000000000000",
"tally_inputs": "",
"tally_gas_limit": 1000000,
"replication_factor": 1,
"consensus_filter": "AA==",
"gas_price": "0",
"gas_limit": 1000000,
"memo": "BQ=="
}
},
{
"request_id": "e220988adad2c99912c5a4a7feb197e04a1a0396de7ca16b5e47dc1b6995b484",
"request_id": "2f1a4631e4f44f75b327b05bc470685d35f81e38b2be215df912c0c733516d60",
"args": {
"version": "0.0.1",
"exec_program_id": "0000000000000000000000000000000000000000000000000000000000000000",
"exec_inputs": "",
"exec_gas_limit": 1000000,
"tally_program_id": "0000000000000000000000000000000000000000000000000000000000000000",
"tally_inputs": "",
"tally_gas_limit": 1000000,
"replication_factor": 1,
"consensus_filter": "AA==",
"gas_price": "0",
"gas_limit": 1000000,
"memo": "Bg=="
}
},
{
"request_id": "2d9d50f861512a9f7041452eddfbff39f2553e1ebb5646d2eecf6733d7c8d2ce",
"request_id": "a42faa4d3136c37ae60c76f2e648a4d3aec0865b1b9fcf688fcbe9caf8007126",
"args": {
"version": "0.0.1",
"exec_program_id": "0000000000000000000000000000000000000000000000000000000000000000",
"exec_inputs": "",
"exec_gas_limit": 1000000,
"tally_program_id": "0000000000000000000000000000000000000000000000000000000000000000",
"tally_inputs": "",
"tally_gas_limit": 1000000,
"replication_factor": 1,
"consensus_filter": "AA==",
"gas_price": "0",
"gas_limit": 1000000,
"memo": "Bw=="
}
},
{
"request_id": "3b8dfa0893f0a24ce3d600fad4ca16fd08ee257efea866145d000e65cf14f04a",
"request_id": "ddddc03d467cb94bcea473231c992cf66678e59645ab906802f8e06891dd9d2d",
"args": {
"version": "0.0.1",
"exec_program_id": "0000000000000000000000000000000000000000000000000000000000000000",
"exec_inputs": "",
"exec_gas_limit": 1000000,
"tally_program_id": "0000000000000000000000000000000000000000000000000000000000000000",
"tally_inputs": "",
"tally_gas_limit": 1000000,
"replication_factor": 1,
"consensus_filter": "AA==",
"gas_price": "0",
"gas_limit": 1000000,
"memo": "CA=="
}
},
{
"request_id": "f180cde27633a009ad05fe86b0ef69c7f2065c3fcf40b103710173829990ce87",
"request_id": "19888f9d7530c6e5db252d6caa112939bbbfa6f1a634311152ffeb2b0e2b45d4",
"args": {
"version": "0.0.1",
"exec_program_id": "0000000000000000000000000000000000000000000000000000000000000000",
"exec_inputs": "",
"exec_gas_limit": 1000000,
"tally_program_id": "0000000000000000000000000000000000000000000000000000000000000000",
"tally_inputs": "",
"tally_gas_limit": 1000000,
"replication_factor": 1,
"consensus_filter": "AA==",
"gas_price": "0",
"gas_limit": 1000000,
"memo": "CQ=="
}
}
Expand Down
9 changes: 6 additions & 3 deletions crates/common/src/msgs/data_requests/execute_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,20 @@ fn json_post_request() {
let exec_inputs = "exec_inputs".to_string();
#[cfg(feature = "cosmwasm")]
let exec_inputs: Bytes = "exec_inputs".as_bytes().into();
let exec_gas_limit = 100;

#[cfg(not(feature = "cosmwasm"))]
let tally_inputs = "tally_inputs".to_string();
#[cfg(feature = "cosmwasm")]
let tally_inputs: Bytes = "tally_inputs".as_bytes().into();
let tally_gas_limit = 100;

#[cfg(not(feature = "cosmwasm"))]
let consensus_filter = "consensus_filter".to_string();
#[cfg(feature = "cosmwasm")]
let consensus_filter: Bytes = "consensus_filter".as_bytes().into();

let gas_price: U128 = 100u128.into();
let gas_limit = 100;

#[cfg(not(feature = "cosmwasm"))]
let memo = "memo".to_string();
Expand All @@ -70,12 +71,13 @@ fn json_post_request() {
version: Version::new(1, 0, 0),
exec_program_id: "exec_program_id".to_string(),
exec_inputs: exec_inputs.clone(),
exec_gas_limit,
tally_program_id: "tally_program_id".to_string(),
tally_inputs: tally_inputs.clone(),
tally_gas_limit,
replication_factor: 1,
consensus_filter: consensus_filter.clone(),
gas_price,
gas_limit,
memo: memo.clone(),
};
let expected_json = json!({
Expand All @@ -84,12 +86,13 @@ fn json_post_request() {
"version": "1.0.0",
"exec_program_id": "exec_program_id",
"exec_inputs": exec_inputs,
"exec_gas_limit": exec_gas_limit,
"tally_program_id": "tally_program_id",
"tally_inputs": tally_inputs,
"tally_gas_limit": tally_gas_limit,
"replication_factor": 1,
"consensus_filter": consensus_filter,
"gas_price": gas_price.to_string(),
"gas_limit": gas_limit,
"memo": memo
},
"seda_payload": seda_payload,
Expand Down
12 changes: 8 additions & 4 deletions crates/common/src/msgs/data_requests/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,20 @@ pub struct DataRequest {
pub exec_program_id: String,
/// Inputs for DR WASM binary
pub exec_inputs: Bytes,
/// The limit to how much gas should be used for executing the DR
pub exec_gas_limit: u64,
/// Identifier of Tally WASM binary
pub tally_program_id: String,
/// Inputs for Tally WASM binary
pub tally_inputs: Bytes,
/// The limit to how much gas should be used for tallying the DR
pub tally_gas_limit: u64,
/// Amount of required DR executors
pub replication_factor: u16,
/// Filter applied before tally execution
pub consensus_filter: Bytes,
/// Amount of SEDA tokens per gas unit
pub gas_price: U128,
/// Maximum of gas units to be used by data request executors to resolve a data request
pub gas_limit: u64,
/// Public info attached to DR
pub memo: Bytes,

Expand Down Expand Up @@ -131,12 +133,13 @@ pub struct PostDataRequestArgs {
pub version: Version,
pub exec_program_id: String,
pub exec_inputs: Bytes,
pub exec_gas_limit: u64,
pub tally_program_id: String,
pub tally_inputs: Bytes,
pub tally_gas_limit: u64,
pub replication_factor: u16,
pub consensus_filter: Bytes,
pub gas_price: U128,
pub gas_limit: u64,
pub memo: Bytes,
}

Expand Down Expand Up @@ -177,12 +180,13 @@ impl TryHashSelf for PostDataRequestArgs {
// I don't think we should decode to hash... expensive in cosmwasm no?
dr_hasher.update(hex::decode(&self.exec_program_id)?);
dr_hasher.update(exec_inputs_hash);
dr_hasher.update(self.exec_gas_limit.to_be_bytes());
dr_hasher.update(hex::decode(&self.tally_program_id)?);
dr_hasher.update(tally_inputs_hash);
dr_hasher.update(self.tally_gas_limit.to_be_bytes());
dr_hasher.update(self.replication_factor.to_be_bytes());
dr_hasher.update(consensus_filter_hash);
dr_hasher.update(self.gas_price.to_be_bytes());
dr_hasher.update(self.gas_limit.to_be_bytes());
dr_hasher.update(memo_hash);

Ok(dr_hasher.finalize().into())
Expand Down
18 changes: 12 additions & 6 deletions crates/common/src/msgs/data_requests/types_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,19 @@ fn json_data_request() {
let exec_inputs = "exec_inputs".to_string();
#[cfg(feature = "cosmwasm")]
let exec_inputs: Bytes = "exec_inputs".as_bytes().into();
let exec_gas_limit = 1;
let tally_program_id = "tally_program_id".to_string();
#[cfg(not(feature = "cosmwasm"))]
let tally_inputs = "tally_inputs".to_string();
#[cfg(feature = "cosmwasm")]
let tally_inputs: Bytes = "tally_inputs".as_bytes().into();
let tally_gas_limit = 1;
let replication_factor = 1;
#[cfg(not(feature = "cosmwasm"))]
let consensus_filter = "consensus_filter".to_string();
#[cfg(feature = "cosmwasm")]
let consensus_filter: Bytes = "consensus_filter".as_bytes().into();
let gas_price: U128 = 1u128.into();
let gas_limit = 1;
#[cfg(not(feature = "cosmwasm"))]
let memo = "memo".to_string();
#[cfg(feature = "cosmwasm")]
Expand All @@ -66,12 +67,13 @@ fn json_data_request() {
"version": version,
"exec_program_id": exec_program_id,
"exec_inputs": exec_inputs,
"exec_gas_limit": exec_gas_limit,
"tally_program_id": tally_program_id,
"tally_inputs": tally_inputs,
"tally_gas_limit": tally_gas_limit,
"replication_factor": replication_factor,
"consensus_filter": consensus_filter,
"gas_price": gas_price,
"gas_limit": gas_limit,
"memo": memo,
"payback_address": payback_address,
"seda_payload": seda_payload,
Expand All @@ -85,12 +87,13 @@ fn json_data_request() {
version: version.parse().unwrap(),
exec_program_id,
exec_inputs,
exec_gas_limit,
tally_program_id,
tally_inputs,
tally_gas_limit,
replication_factor,
consensus_filter,
gas_price,
gas_limit,
memo,
payback_address,
seda_payload,
Expand Down Expand Up @@ -149,18 +152,19 @@ fn json_post_data_request_args() {
let exec_inputs = "exec_inputs".to_string();
#[cfg(feature = "cosmwasm")]
let exec_inputs: Bytes = "exec_inputs".as_bytes().into();
let exec_gas_limit = 1;
let tally_program_id = "tally_program_id".to_string();
#[cfg(not(feature = "cosmwasm"))]
let tally_inputs = "tally_inputs".to_string();
#[cfg(feature = "cosmwasm")]
let tally_inputs: Bytes = "tally_inputs".as_bytes().into();
let tally_gas_limit = 1;
let replication_factor = 1;
#[cfg(not(feature = "cosmwasm"))]
let consensus_filter = "consensus_filter".to_string();
#[cfg(feature = "cosmwasm")]
let consensus_filter: Bytes = "consensus_filter".as_bytes().into();
let gas_price: U128 = 1u128.into();
let gas_limit = 1;
#[cfg(not(feature = "cosmwasm"))]
let memo = "memo".to_string();
#[cfg(feature = "cosmwasm")]
Expand All @@ -170,25 +174,27 @@ fn json_post_data_request_args() {
"version": version,
"exec_program_id": exec_program_id,
"exec_inputs": exec_inputs,
"exec_gas_limit": exec_gas_limit,
"tally_program_id": tally_program_id,
"tally_inputs": tally_inputs,
"tally_gas_limit": tally_gas_limit,
"replication_factor": replication_factor,
"consensus_filter": consensus_filter,
"gas_price": gas_price,
"gas_limit": gas_limit,
"memo": memo,
});

let msg = PostDataRequestArgs {
version: version.parse().unwrap(),
exec_program_id,
exec_inputs,
exec_gas_limit,
tally_program_id,
tally_inputs,
tally_gas_limit,
replication_factor,
consensus_filter,
gas_price,
gas_limit,
memo,
};

Expand Down