Skip to content

Commit

Permalink
Include token owners in TransactionTokenBalances (backport #20642) (#…
Browse files Browse the repository at this point in the history
…20677)

* Include token owners in TransactionTokenBalances (#20642)

* Cache owners in TransactionTokenBalances

* Light cleanup

* Use return struct, and remove pub

* Single-use statements

* Why not, just do the whole crate

* Add metrics

* Make datapoint_debug to prevent spam unless troubleshooting

(cherry picked from commit e806fa6)

# Conflicts:
#	ledger/src/blockstore.rs
#	transaction-status/Cargo.toml
#	transaction-status/src/token_balances.rs

* Fix conflicts

Co-authored-by: Tyera Eulberg <teulberg@gmail.com>
Co-authored-by: Tyera Eulberg <tyera@solana.com>
  • Loading branch information
3 people authored Oct 14, 2021
1 parent e0280a6 commit 88e6f41
Show file tree
Hide file tree
Showing 17 changed files with 213 additions and 137 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions ledger/src/blockstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8407,6 +8407,7 @@ pub mod tests {
amount: "11".to_string(),
ui_amount_string: "1.1".to_string(),
},
owner: Pubkey::new_unique().to_string(),
}]),
post_token_balances: Some(vec![TransactionTokenBalance {
account_index: 0,
Expand All @@ -8417,6 +8418,7 @@ pub mod tests {
amount: "11".to_string(),
ui_amount_string: "1.1".to_string(),
},
owner: Pubkey::new_unique().to_string(),
}]),
rewards: Some(vec![Reward {
pubkey: "My11111111111111111111111111111111111111111".to_string(),
Expand Down
3 changes: 3 additions & 0 deletions programs/bpf/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions storage-proto/proto/confirmed_block.proto
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ message TokenBalance {
uint32 account_index = 1;
string mint = 2;
UiTokenAmount ui_token_amount = 3;
string owner = 4;
}

message UiTokenAmount {
Expand Down
2 changes: 2 additions & 0 deletions storage-proto/src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ impl From<TransactionTokenBalance> for generated::TokenBalance {
amount: value.ui_token_amount.amount,
ui_amount_string: value.ui_token_amount.ui_amount_string,
}),
owner: value.owner,
}
}
}
Expand Down Expand Up @@ -435,6 +436,7 @@ impl From<generated::TokenBalance> for TransactionTokenBalance {
)
},
},
owner: value.owner,
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions storage-proto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ pub struct StoredTransactionTokenBalance {
pub account_index: u8,
pub mint: String,
pub ui_token_amount: StoredTokenAmount,
#[serde(deserialize_with = "default_on_eof")]
pub owner: String,
}

impl From<StoredTransactionTokenBalance> for TransactionTokenBalance {
Expand All @@ -119,11 +121,13 @@ impl From<StoredTransactionTokenBalance> for TransactionTokenBalance {
account_index,
mint,
ui_token_amount,
owner,
} = value;
Self {
account_index,
mint,
ui_token_amount: ui_token_amount.into(),
owner,
}
}
}
Expand All @@ -134,11 +138,13 @@ impl From<TransactionTokenBalance> for StoredTransactionTokenBalance {
account_index,
mint,
ui_token_amount,
owner,
} = value;
Self {
account_index,
mint,
ui_token_amount: ui_token_amount.into(),
owner,
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions transaction-status/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ bincode = "1.3.1"
bs58 = "0.3.1"
Inflector = "0.11.4"
lazy_static = "1.4.0"
log = "0.4.11"
serde = "1.0.122"
serde_derive = "1.0.103"
serde_json = "1.0.56"
solana-account-decoder = { path = "../account-decoder", version = "=1.8.1" }
solana-measure = { path = "../measure", version = "=1.8.1" }
solana-metrics = { path = "../metrics", version = "=1.8.1" }
solana-sdk = { path = "../sdk", version = "=1.8.1" }
solana-runtime = { path = "../runtime", version = "=1.8.1" }
solana-vote-program = { path = "../programs/vote", version = "=1.8.1" }
Expand Down
45 changes: 27 additions & 18 deletions transaction-status/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,26 @@ pub mod parse_token;
pub mod parse_vote;
pub mod token_balances;

pub use crate::extract_memos::extract_and_fmt_memos;
use crate::{
parse_accounts::{parse_accounts, ParsedAccount},
parse_instruction::{parse, ParsedInstruction},
pub use {crate::extract_memos::extract_and_fmt_memos, solana_runtime::bank::RewardType};
use {
crate::{
parse_accounts::{parse_accounts, ParsedAccount},
parse_instruction::{parse, ParsedInstruction},
},
solana_account_decoder::parse_token::UiTokenAmount,
solana_sdk::{
clock::{Slot, UnixTimestamp},
commitment_config::CommitmentConfig,
deserialize_utils::default_on_eof,
instruction::CompiledInstruction,
message::{Message, MessageHeader},
pubkey::Pubkey,
sanitize::Sanitize,
signature::Signature,
transaction::{Result, Transaction, TransactionError},
},
std::fmt,
};
use solana_account_decoder::parse_token::UiTokenAmount;
pub use solana_runtime::bank::RewardType;
use solana_sdk::{
clock::{Slot, UnixTimestamp},
commitment_config::CommitmentConfig,
deserialize_utils::default_on_eof,
instruction::CompiledInstruction,
message::{Message, MessageHeader},
pubkey::Pubkey,
sanitize::Sanitize,
signature::Signature,
transaction::{Result, Transaction, TransactionError},
};
use std::fmt;
/// A duplicate representation of an Instruction for pretty JSON serialization
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase", untagged)]
Expand Down Expand Up @@ -126,6 +127,7 @@ pub struct TransactionTokenBalance {
pub account_index: u8,
pub mint: String,
pub ui_token_amount: UiTokenAmount,
pub owner: String,
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
Expand All @@ -134,6 +136,8 @@ pub struct UiTransactionTokenBalance {
pub account_index: u8,
pub mint: String,
pub ui_token_amount: UiTokenAmount,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub owner: Option<String>,
}

impl From<TransactionTokenBalance> for UiTransactionTokenBalance {
Expand All @@ -142,6 +146,11 @@ impl From<TransactionTokenBalance> for UiTransactionTokenBalance {
account_index: token_balance.account_index,
mint: token_balance.mint,
ui_token_amount: token_balance.ui_token_amount,
owner: if !token_balance.owner.is_empty() {
Some(token_balance.owner)
} else {
None
},
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions transaction-status/src/parse_accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ pub fn parse_accounts(message: &Message) -> Vec<ParsedAccount> {

#[cfg(test)]
mod test {
use super::*;
use solana_sdk::message::MessageHeader;
use {super::*, solana_sdk::message::MessageHeader};

#[test]
fn test_parse_accounts() {
Expand Down
24 changes: 14 additions & 10 deletions transaction-status/src/parse_associated_token.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use crate::parse_instruction::{
check_num_accounts, ParsableProgram, ParseInstructionError, ParsedInstructionEnum,
use {
crate::parse_instruction::{
check_num_accounts, ParsableProgram, ParseInstructionError, ParsedInstructionEnum,
},
serde_json::json,
solana_sdk::{instruction::CompiledInstruction, pubkey::Pubkey},
};
use serde_json::json;
use solana_sdk::{instruction::CompiledInstruction, pubkey::Pubkey};

// A helper function to convert spl_associated_token_account_v1_0::id() as spl_sdk::pubkey::Pubkey
// to solana_sdk::pubkey::Pubkey
Expand Down Expand Up @@ -47,12 +49,14 @@ fn check_num_associated_token_accounts(

#[cfg(test)]
mod test {
use super::*;
use spl_associated_token_account_v1_0::{
create_associated_token_account,
solana_program::{
instruction::CompiledInstruction as SplAssociatedTokenCompiledInstruction,
message::Message, pubkey::Pubkey as SplAssociatedTokenPubkey,
use {
super::*,
spl_associated_token_account_v1_0::{
create_associated_token_account,
solana_program::{
instruction::CompiledInstruction as SplAssociatedTokenCompiledInstruction,
message::Message, pubkey::Pubkey as SplAssociatedTokenPubkey,
},
},
};

Expand Down
26 changes: 15 additions & 11 deletions transaction-status/src/parse_bpf_loader.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use crate::parse_instruction::{
check_num_accounts, ParsableProgram, ParseInstructionError, ParsedInstructionEnum,
};
use bincode::deserialize;
use serde_json::json;
use solana_sdk::{
instruction::CompiledInstruction, loader_instruction::LoaderInstruction,
loader_upgradeable_instruction::UpgradeableLoaderInstruction, pubkey::Pubkey,
use {
crate::parse_instruction::{
check_num_accounts, ParsableProgram, ParseInstructionError, ParsedInstructionEnum,
},
bincode::deserialize,
serde_json::json,
solana_sdk::{
instruction::CompiledInstruction, loader_instruction::LoaderInstruction,
loader_upgradeable_instruction::UpgradeableLoaderInstruction, pubkey::Pubkey,
},
};

pub fn parse_bpf_loader(
Expand Down Expand Up @@ -154,9 +156,11 @@ fn check_num_bpf_upgradeable_loader_accounts(

#[cfg(test)]
mod test {
use super::*;
use serde_json::Value;
use solana_sdk::{message::Message, pubkey};
use {
super::*,
serde_json::Value,
solana_sdk::{message::Message, pubkey},
};

#[test]
fn test_parse_bpf_loader_instructions() {
Expand Down
39 changes: 20 additions & 19 deletions transaction-status/src/parse_instruction.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
use crate::{
extract_memos::{spl_memo_id_v1, spl_memo_id_v3},
parse_associated_token::{parse_associated_token, spl_associated_token_id_v1_0},
parse_bpf_loader::{parse_bpf_loader, parse_bpf_upgradeable_loader},
parse_stake::parse_stake,
parse_system::parse_system,
parse_token::parse_token,
parse_vote::parse_vote,
use {
crate::{
extract_memos::{spl_memo_id_v1, spl_memo_id_v3},
parse_associated_token::{parse_associated_token, spl_associated_token_id_v1_0},
parse_bpf_loader::{parse_bpf_loader, parse_bpf_upgradeable_loader},
parse_stake::parse_stake,
parse_system::parse_system,
parse_token::parse_token,
parse_vote::parse_vote,
},
inflector::Inflector,
serde_json::Value,
solana_account_decoder::parse_token::spl_token_id_v2_0,
solana_sdk::{instruction::CompiledInstruction, pubkey::Pubkey, stake, system_program},
std::{
collections::HashMap,
str::{from_utf8, Utf8Error},
},
thiserror::Error,
};
use inflector::Inflector;
use serde_json::Value;
use solana_account_decoder::parse_token::spl_token_id_v2_0;
use solana_sdk::{instruction::CompiledInstruction, pubkey::Pubkey, stake, system_program};
use std::{
collections::HashMap,
str::{from_utf8, Utf8Error},
};
use thiserror::Error;

lazy_static! {
static ref ASSOCIATED_TOKEN_PROGRAM_ID: Pubkey = spl_associated_token_id_v1_0();
Expand Down Expand Up @@ -150,8 +152,7 @@ pub(crate) fn check_num_accounts(

#[cfg(test)]
mod test {
use super::*;
use serde_json::json;
use {super::*, serde_json::json};

#[test]
fn test_parse() {
Expand Down
32 changes: 18 additions & 14 deletions transaction-status/src/parse_stake.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use crate::parse_instruction::{
check_num_accounts, ParsableProgram, ParseInstructionError, ParsedInstructionEnum,
};
use bincode::deserialize;
use serde_json::{json, Map};
use solana_sdk::{
instruction::CompiledInstruction, pubkey::Pubkey, stake::instruction::StakeInstruction,
use {
crate::parse_instruction::{
check_num_accounts, ParsableProgram, ParseInstructionError, ParsedInstructionEnum,
},
bincode::deserialize,
serde_json::{json, Map},
solana_sdk::{
instruction::CompiledInstruction, pubkey::Pubkey, stake::instruction::StakeInstruction,
},
};

pub fn parse_stake(
Expand Down Expand Up @@ -275,13 +277,15 @@ fn check_num_stake_accounts(accounts: &[u8], num: usize) -> Result<(), ParseInst

#[cfg(test)]
mod test {
use super::*;
use solana_sdk::{
message::Message,
pubkey::Pubkey,
stake::{
instruction::{self, LockupArgs},
state::{Authorized, Lockup, StakeAuthorize},
use {
super::*,
solana_sdk::{
message::Message,
pubkey::Pubkey,
stake::{
instruction::{self, LockupArgs},
state::{Authorized, Lockup, StakeAuthorize},
},
},
};

Expand Down
Loading

0 comments on commit 88e6f41

Please sign in to comment.