-
Notifications
You must be signed in to change notification settings - Fork 14
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
improve gas estimation #267
Closed
+149
−24
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
-- This file should undo anything in `up.sql` | ||
ALTER TABLE gas_estimations DROP COLUMN ibc_unshielding_transfer; | ||
ALTER TABLE gas_estimations DROP COLUMN ibc_shielding_transfer; |
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,3 @@ | ||
-- Your SQL goes here | ||
ALTER TABLE gas_estimations ADD COLUMN ibc_unshielding_transfer INT NOT NULL; | ||
ALTER TABLE gas_estimations ADD COLUMN ibc_shielding_transfer INT NOT NULL; |
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
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 |
---|---|---|
|
@@ -4,6 +4,7 @@ use std::fmt::Display; | |
use namada_governance::{InitProposalData, VoteProposalData}; | ||
use namada_sdk::address::Address; | ||
use namada_sdk::borsh::BorshDeserialize; | ||
use namada_sdk::events::extend::MaspTxRef; | ||
use namada_sdk::key::common::PublicKey; | ||
use namada_sdk::token::Transfer; | ||
use namada_sdk::uint::Uint; | ||
|
@@ -274,9 +275,8 @@ pub struct Transaction { | |
} | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct Transaction2 { | ||
pub wrapper: WrapperTransaction, | ||
pub inners: InnerTransaction, | ||
pub struct MaspSectionData { | ||
pub total_notes: u64, | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
|
@@ -300,6 +300,7 @@ pub struct InnerTransaction { | |
pub memo: Option<String>, | ||
pub data: Option<String>, | ||
pub extra_sections: HashMap<Id, Vec<u8>>, | ||
pub notes: u64, | ||
pub exit_code: TransactionExitStatus, | ||
} | ||
|
||
|
@@ -359,6 +360,8 @@ impl Transaction { | |
let gas_used = block_results | ||
.gas_used(&wrapper_tx_id) | ||
.map(|gas| gas.parse::<u64>().unwrap()); | ||
let masp_refs = | ||
block_results.masp_refs(&wrapper_tx_id, index as u64); | ||
|
||
let fee = Fee { | ||
gas: Uint::from(wrapper.gas_limit).to_string(), | ||
|
@@ -459,13 +462,36 @@ impl Transaction { | |
acc | ||
}); | ||
|
||
let notes = masp_refs.clone().into_iter().map(|masp_ref| { | ||
match masp_ref { | ||
MaspTxRef::MaspSection(masp_tx_id) => { | ||
transaction | ||
.get_masp_section(&masp_tx_id) | ||
.map(|bundle| bundle.clone().into_data().sapling_bundle().map(|bundle| bundle.shielded_spends.len() + bundle.shielded_outputs.len()).unwrap_or_default()).unwrap_or_default() as u64 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here and down below it might be nice to also account for the length of the |
||
}, | ||
MaspTxRef::IbcData(hash) => { | ||
transaction.get_data_section(&hash).map(|section| match namada_sdk::ibc::decode_message::<Transfer>(§ion) { | ||
Ok(namada_ibc::IbcMessage::Envelope(msg_envelope)) => { | ||
if let Some(bundle) = namada_sdk::ibc::extract_masp_tx_from_envelope(&msg_envelope) { | ||
bundle.clone().into_data().sapling_bundle().map(|bundle| bundle.shielded_spends.len() + bundle.shielded_outputs.len()).unwrap_or_default() as u64 | ||
} else { | ||
0 | ||
} | ||
}, | ||
_ => 0, | ||
}).unwrap_or_default() | ||
}, | ||
} | ||
}).sum::<u64>(); | ||
|
||
let inner_tx = InnerTransaction { | ||
tx_id: inner_tx_id, | ||
index, | ||
wrapper_id: wrapper_tx_id.clone(), | ||
memo, | ||
data: encoded_tx_data, | ||
extra_sections, | ||
notes, | ||
exit_code: inner_tx_status, | ||
kind: tx_kind, | ||
}; | ||
|
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we should check if this specific masp ref belongs to this inner tx
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes so, we'd need to check if the inner tx we are currently analyzing is a successful masp tx and if so pop from the head of the
masp_refs
vector the next element and run thematch
expression here above. It's a bit unlucky cause the events don't carry the exact inner tx index of that masp data (it's not needed when constructing the local state of a shielded wallet) so we kind of have to do this manually in here. We should have thebatch
event somewhere here so that we can check the exit code of this inner tx. Understanding if it is a masp tx could be slightly more complex: we'd need to deserialize the tx data and see if it is a transfer, ibc transfer or neither. If none, then this is not a masp tx. If it is either a transfer or an ibc transfer we should check if it contains the pointer to the sameMaspTxRef
that we expect: if so we extract, otherwise we skip