Skip to content
This repository has been archived by the owner on Jul 27, 2022. It is now read-only.

Commit

Permalink
Problem (Fix #1069): blocks with multiple txs may fail light client a…
Browse files Browse the repository at this point in the history
…pp hash check

Solution:
- Change BTreeMap to IndexMap
  • Loading branch information
yihuang committed Feb 21, 2020
1 parent 8183883 commit 60175f5
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 8 deletions.
1 change: 1 addition & 0 deletions 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 client-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ parity-scale-codec = { features = ["derive"], version = "1.1" }
websocket = { version = "0.24", default-features = false, features = ["sync"], optional = true }
tendermint = { git = "https://github.com/crypto-com/tendermint-rs.git", default-features = false, rev = "db982c2437fe72c7a03942fc2bddf490f2332364" }
itertools = "0.8"
indexmap = "1.3"

[dev-dependencies]
quickcheck = "0.9"
Expand Down
8 changes: 4 additions & 4 deletions client-common/src/tendermint/types/block_results.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#![allow(missing_docs)]
use std::collections::BTreeMap;
use std::convert::TryFrom;
use std::str::{from_utf8, FromStr};

use base64;
use indexmap::IndexMap;
use serde::Deserialize;

use chain_core::common::{TendermintEventKey, TendermintEventType};
Expand Down Expand Up @@ -56,11 +56,11 @@ pub struct Attribute {

impl BlockResults {
/// Returns transaction ids and the corresponding fees in block results
pub fn fees(&self) -> Result<BTreeMap<TxId, Fee>> {
pub fn fees(&self) -> Result<IndexMap<TxId, Fee>> {
match &self.results.deliver_tx {
None => Ok(BTreeMap::default()),
None => Ok(IndexMap::default()),
Some(deliver_tx) => {
let mut fees: BTreeMap<TxId, Fee> = BTreeMap::new();
let mut fees: IndexMap<TxId, Fee> = IndexMap::new();

for transaction in deliver_tx.iter() {
for event in transaction.events.iter() {
Expand Down
4 changes: 2 additions & 2 deletions client-core/src/wallet/syncer.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![allow(missing_docs)]
use indexmap::IndexMap;
use itertools::{izip, Itertools};
use non_empty_vec::NonEmpty;
use std::sync::mpsc::Sender;
Expand All @@ -18,7 +19,6 @@ use super::syncer_logic::handle_blocks;
use crate::service;
use crate::service::{KeyService, SyncState, Wallet, WalletState, WalletStateMemento};
use crate::TransactionObfuscation;
use std::collections::BTreeMap;

/// Transaction decryptor interface for wallet synchronizer
pub trait TxDecryptor: Clone + Send + Sync {
Expand Down Expand Up @@ -484,7 +484,7 @@ pub(crate) struct FilteredBlock {
/// Block time
pub block_time: Time,
/// List of successfully committed transaction ids in this block and their fees
pub valid_transaction_fees: BTreeMap<TxId, Fee>,
pub valid_transaction_fees: IndexMap<TxId, Fee>,
/// Bloom filter for view keys and staking addresses
pub block_filter: BlockFilter,
/// List of successfully committed transaction of transactions that may need to be queried against
Expand Down
4 changes: 2 additions & 2 deletions client-core/src/wallet/syncer_logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ fn calculate_balance_change<'a>(

#[cfg(test)]
mod tests {
use indexmap::IndexMap;
use secstr::SecUtf8;
use std::str::FromStr;

Expand All @@ -243,7 +244,6 @@ mod tests {
use crate::service::load_wallet;
use crate::types::WalletKind;
use crate::wallet::{DefaultWalletClient, WalletClient};
use std::collections::BTreeMap;

fn create_test_wallet(n: usize) -> Result<Vec<Wallet>> {
let storage = MemoryStorage::default();
Expand Down Expand Up @@ -302,7 +302,7 @@ mod tests {
.map(|tx| tx.id())
.chain(other_txs.iter().map(|tx| tx.id()))
.collect();
let mut valid_transaction_fees = BTreeMap::new();
let mut valid_transaction_fees = IndexMap::new();
for txid in valid_transaction_ids.iter() {
valid_transaction_fees.insert(*txid, Fee::new(Coin::one()));
}
Expand Down

0 comments on commit 60175f5

Please sign in to comment.