Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
1534761
GH-601: Introduce SentPayable Table (#611)
utkarshg6 Apr 4, 2025
df415c0
GH-608: change the trait object to support SentPayables
utkarshg6 Apr 10, 2025
f9f43be
Revert "GH-608: change the trait object to support SentPayables"
utkarshg6 Apr 11, 2025
17360c5
GH-608: introduce sent payable dao
utkarshg6 Apr 11, 2025
b9c56ce
GH-608: add boilerplate code
utkarshg6 Apr 11, 2025
00dba17
GH-608: implement insert_new_records
utkarshg6 Apr 14, 2025
0779066
GH-608: add test cases for the panic and error clause for the insert …
utkarshg6 Apr 15, 2025
954299a
GH-608: introduce builder pattern for the Tx
utkarshg6 Apr 15, 2025
46ab105
GH-608: implement get_tx_identifiers
utkarshg6 Apr 16, 2025
b5e11b5
GH-608: implement retrieve_pending_txs()
utkarshg6 Apr 17, 2025
df8e82a
GH-608: add more assertions for the retrieve_pending_txs() and implem…
utkarshg6 Apr 17, 2025
df0ea02
GH-608: rename time_t in fn names to unix_timestamp
utkarshg6 Apr 17, 2025
5e198b2
GH-608: refactor sent_payable_dao.rs
utkarshg6 Apr 17, 2025
8871b72
GH-608: add stronger tests for insert_new_records()
utkarshg6 Apr 18, 2025
5b99e07
GH-608: retrieve txs conditionally
utkarshg6 Apr 18, 2025
64f14a0
GH-608: change SQL to uppercase wherever necessary
utkarshg6 Apr 18, 2025
41e6ea1
GH-608: add RetrieveCondtion::ToRetry
utkarshg6 Apr 18, 2025
fe1a66f
GH-608: add constant RETRY_THRESHOLD_SECS
utkarshg6 Apr 18, 2025
2201030
GH-608: implement display and from_str() for TxStatus
utkarshg6 Apr 21, 2025
2352699
GH-608: implement retrieve_condition_display_works
utkarshg6 Apr 21, 2025
6d49640
GH-608: update the query for txs_to_retry and reorder trait functions
utkarshg6 Apr 21, 2025
7b1fefe
GH-608: change SQL query for txs to retry
utkarshg6 Apr 24, 2025
a953c37
GH-608: remove RETRY_THRESHOLD_SECS
utkarshg6 Apr 24, 2025
918fc8f
GH-608: remove retried column from the sent_payable table
utkarshg6 Apr 25, 2025
1514096
GH-608: add ability to retrieve tx by hash
utkarshg6 Apr 25, 2025
9fade80
GH-608: add the ability to update statuses
utkarshg6 Apr 25, 2025
b27620a
GH-608: add types for TxHash and RowID
utkarshg6 Apr 25, 2025
c63c6f5
GH-608: add test for deleting records
utkarshg6 Apr 25, 2025
9d42af1
GH-608: add fn for deleting records
utkarshg6 Apr 25, 2025
f4e92df
GH-608: add more TODOs
utkarshg6 Apr 25, 2025
5eab479
GH-608: error testing
utkarshg6 Apr 29, 2025
b7d35d8
GH-608: write tests for error handling while deleting records
utkarshg6 Apr 30, 2025
b164cf9
GH-608: add more TODOs
utkarshg6 Apr 30, 2025
8d5cc0a
GH-608: return SqlExecutionFailed in insert, change_status and delete…
utkarshg6 May 1, 2025
10ab113
GH-608: add better error handling for delete records
utkarshg6 May 1, 2025
875da42
GH-608: change the signature of delete_records() to accept Hashset
utkarshg6 May 1, 2025
4c4515e
GH-608: remove unused SentPayableDaoError
utkarshg6 May 1, 2025
9783e3b
GH-608: use the variant EmptyInput
utkarshg6 May 1, 2025
c90b97b
GH-608: add more validations for insert_new_records
utkarshg6 May 2, 2025
5835ed2
GH-608: test all errors
utkarshg6 May 2, 2025
d44215e
GH-608: remove unnecessary TODOs
utkarshg6 May 2, 2025
e8049c4
GH-608: perform some cleanup
utkarshg6 May 2, 2025
545bfeb
GH-608: eliminate clippy warnings
utkarshg6 May 2, 2025
a010215
GH-608: review 1 changes
utkarshg6 May 9, 2025
9f47ee6
GH-608: remove clippy warnings
utkarshg6 May 9, 2025
13340d5
GH-608: review 2 changes
utkarshg6 May 15, 2025
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
2 changes: 1 addition & 1 deletion masq_lib/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::data_version::DataVersion;
use const_format::concatcp;

pub const DEFAULT_CHAIN: Chain = Chain::PolyMainnet;
pub const CURRENT_SCHEMA_VERSION: usize = 10;
pub const CURRENT_SCHEMA_VERSION: usize = 11;

pub const HIGHEST_RANDOM_CLANDESTINE_PORT: u16 = 9999;
pub const HTTP_PORT: u16 = 80;
Expand Down
2 changes: 2 additions & 0 deletions node/src/accountant/db_access_objects/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ pub mod banned_dao;
pub mod payable_dao;
pub mod pending_payable_dao;
pub mod receivable_dao;
pub mod sent_payable_dao;
mod test_utils;
pub mod utils;
77 changes: 40 additions & 37 deletions node/src/accountant/db_access_objects/payable_dao.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::accountant::db_big_integer::big_int_db_processor::{BigIntDbProcessor,
use crate::accountant::db_big_integer::big_int_divider::BigIntDivider;
use crate::accountant::db_access_objects::utils;
use crate::accountant::db_access_objects::utils::{
sum_i128_values_from_table, to_time_t, AssemblerFeeder, CustomQuery, DaoFactoryReal,
sum_i128_values_from_table, to_unix_timestamp, AssemblerFeeder, CustomQuery, DaoFactoryReal,
RangeStmConfig, TopStmConfig, VigilantRusqliteFlatten,
};
use crate::accountant::db_access_objects::payable_dao::mark_pending_payable_associated_functions::{
Expand Down Expand Up @@ -100,7 +100,7 @@ impl PayableDao for PayableDaoReal {
let update_clause_with_compensated_overflow = "update payable set \
balance_high_b = :balance_high_b, balance_low_b = :balance_low_b where wallet_address = :wallet";

let last_paid_timestamp = to_time_t(timestamp);
let last_paid_timestamp = to_unix_timestamp(timestamp);
let params = SQLParamsBuilder::default()
.key(WalletAddress(wallet))
.wei_change(WeiChange::new(
Expand Down Expand Up @@ -158,7 +158,7 @@ impl PayableDao for PayableDaoReal {
pending_payable_rowid = null where pending_payable_rowid = :rowid";

let i64_rowid = checked_conversion::<u64, i64>(pending_payable_fingerprint.rowid);
let last_paid = to_time_t(pending_payable_fingerprint.timestamp);
let last_paid = to_unix_timestamp(pending_payable_fingerprint.timestamp);
let params = SQLParamsBuilder::default()
.key( PendingPayableRowid(&i64_rowid))
.wei_change(WeiChange::new( "balance", pending_payable_fingerprint.amount, WeiChangeDirection::Subtraction))
Expand Down Expand Up @@ -196,7 +196,7 @@ impl PayableDao for PayableDaoReal {
balance_wei: checked_conversion::<i128, u128>(BigIntDivider::reconstitute(
high_b, low_b,
)),
last_paid_timestamp: utils::from_time_t(last_paid_timestamp),
last_paid_timestamp: utils::from_unix_timestamp(last_paid_timestamp),
pending_payable_opt: None,
})
}
Expand Down Expand Up @@ -282,7 +282,7 @@ impl PayableDao for PayableDaoReal {
balance_wei: checked_conversion::<i128, u128>(BigIntDivider::reconstitute(
high_bytes, low_bytes,
)),
last_paid_timestamp: utils::from_time_t(last_paid_timestamp),
last_paid_timestamp: utils::from_unix_timestamp(last_paid_timestamp),
pending_payable_opt: match rowid {
Some(rowid) => Some(PendingPayableId::new(
u64::try_from(rowid).unwrap(),
Expand Down Expand Up @@ -338,7 +338,7 @@ impl PayableDaoReal {
balance_wei: checked_conversion::<i128, u128>(BigIntDivider::reconstitute(
high_bytes, low_bytes,
)),
last_paid_timestamp: utils::from_time_t(last_paid_timestamp),
last_paid_timestamp: utils::from_unix_timestamp(last_paid_timestamp),
pending_payable_opt: rowid_opt.map(|rowid| {
let hash_str =
hash_opt.expect("database corrupt; missing hash but existing rowid");
Expand Down Expand Up @@ -541,7 +541,7 @@ mod mark_pending_payable_associated_functions {
#[cfg(test)]
mod tests {
use super::*;
use crate::accountant::db_access_objects::utils::{from_time_t, now_time_t, to_time_t};
use crate::accountant::db_access_objects::utils::{from_unix_timestamp, current_unix_timestamp, to_unix_timestamp};
use crate::accountant::gwei_to_wei;
use crate::accountant::db_access_objects::payable_dao::mark_pending_payable_associated_functions::explanatory_extension;
use crate::accountant::test_utils::{assert_account_creation_fn_fails_on_finding_wrong_columns_and_value_types, make_pending_payable_fingerprint, trick_rusqlite_with_read_only_conn};
Expand Down Expand Up @@ -577,7 +577,10 @@ mod tests {
let status = subject.account_status(&wallet).unwrap();
assert_eq!(status.wallet, wallet);
assert_eq!(status.balance_wei, 1234);
assert_eq!(to_time_t(status.last_paid_timestamp), to_time_t(now));
assert_eq!(
to_unix_timestamp(status.last_paid_timestamp),
to_unix_timestamp(now)
);
}

#[test]
Expand Down Expand Up @@ -616,8 +619,8 @@ mod tests {
assert_eq!(status.wallet, wallet);
assert_eq!(status.balance_wei, expected_balance);
assert_eq!(
to_time_t(status.last_paid_timestamp),
to_time_t(SystemTime::UNIX_EPOCH)
to_unix_timestamp(status.last_paid_timestamp),
to_unix_timestamp(SystemTime::UNIX_EPOCH)
);
};
assert_account(wallet, initial_value + balance_change);
Expand Down Expand Up @@ -653,8 +656,8 @@ mod tests {
assert_eq!(status.wallet, wallet);
assert_eq!(status.balance_wei, initial_value + balance_change);
assert_eq!(
to_time_t(status.last_paid_timestamp),
to_time_t(SystemTime::UNIX_EPOCH)
to_unix_timestamp(status.last_paid_timestamp),
to_unix_timestamp(SystemTime::UNIX_EPOCH)
);
}

Expand Down Expand Up @@ -746,13 +749,13 @@ mod tests {
PayableAccount {
wallet: wallet_0,
balance_wei: u128::try_from(BigIntDivider::reconstitute(12345, 1)).unwrap(),
last_paid_timestamp: from_time_t(45678),
last_paid_timestamp: from_unix_timestamp(45678),
pending_payable_opt: None,
},
PayableAccount {
wallet: wallet_1,
balance_wei: u128::try_from(BigIntDivider::reconstitute(0, i64::MAX)).unwrap(),
last_paid_timestamp: from_time_t(150_000_000),
last_paid_timestamp: from_unix_timestamp(150_000_000),
pending_payable_opt: Some(PendingPayableId::new(
pending_payable_rowid_1,
make_tx_hash(0)
Expand All @@ -762,7 +765,7 @@ mod tests {
PayableAccount {
wallet: wallet_2,
balance_wei: u128::try_from(BigIntDivider::reconstitute(3, 0)).unwrap(),
last_paid_timestamp: from_time_t(151_000_000),
last_paid_timestamp: from_unix_timestamp(151_000_000),
pending_payable_opt: Some(PendingPayableId::new(
pending_payable_rowid_2,
make_tx_hash(0)
Expand Down Expand Up @@ -907,12 +910,12 @@ mod tests {
let hash_1 = make_tx_hash(12345);
let rowid_1 = 789;
let previous_timestamp_1_s = 190_000_000;
let new_payable_timestamp_1 = from_time_t(199_000_000);
let new_payable_timestamp_1 = from_unix_timestamp(199_000_000);
let wallet_1 = make_wallet("bobble");
let hash_2 = make_tx_hash(54321);
let rowid_2 = 792;
let previous_timestamp_2_s = 187_100_000;
let new_payable_timestamp_2 = from_time_t(191_333_000);
let new_payable_timestamp_2 = from_unix_timestamp(191_333_000);
let wallet_2 = make_wallet("booble bobble");
{
insert_payable_record_fn(
Expand Down Expand Up @@ -946,8 +949,8 @@ mod tests {
amount: balance_change_2,
process_error: None,
};
let previous_timestamp_1 = from_time_t(previous_timestamp_1_s);
let previous_timestamp_2 = from_time_t(previous_timestamp_2_s);
let previous_timestamp_1 = from_unix_timestamp(previous_timestamp_1_s);
let previous_timestamp_2 = from_unix_timestamp(previous_timestamp_2_s);
TestSetupValuesHolder {
fingerprint_1,
fingerprint_2,
Expand Down Expand Up @@ -1203,13 +1206,13 @@ mod tests {
PayableAccount {
wallet: make_wallet("foobar"),
balance_wei: 1234567890123456 as u128,
last_paid_timestamp: from_time_t(111_111_111),
last_paid_timestamp: from_unix_timestamp(111_111_111),
pending_payable_opt: None
},
PayableAccount {
wallet: make_wallet("barfoo"),
balance_wei: 1234567890123456 as u128,
last_paid_timestamp: from_time_t(111_111_111),
last_paid_timestamp: from_unix_timestamp(111_111_111),
pending_payable_opt: None
},
]
Expand Down Expand Up @@ -1304,7 +1307,7 @@ mod tests {
//Accounts of balances smaller than one gwei don't qualify.
//Two accounts differ only in debt's age but not balance which allows to check doubled ordering,
//here by balance and then by age.
let now = now_time_t();
let now = current_unix_timestamp();
let main_test_setup = accounts_for_tests_of_top_records(now);
let subject = custom_query_test_body_for_payable(
"custom_query_in_top_records_mode_with_default_ordering",
Expand All @@ -1324,13 +1327,13 @@ mod tests {
PayableAccount {
wallet: Wallet::new("0x2222222222222222222222222222222222222222"),
balance_wei: 7_562_000_300_000,
last_paid_timestamp: from_time_t(now - 86_001),
last_paid_timestamp: from_unix_timestamp(now - 86_001),
pending_payable_opt: None
},
PayableAccount {
wallet: Wallet::new("0x5555555555555555555555555555555555555555"),
balance_wei: 10_000_000_100,
last_paid_timestamp: from_time_t(now - 86_401),
last_paid_timestamp: from_unix_timestamp(now - 86_401),
pending_payable_opt: Some(PendingPayableId::new(
1,
H256::from_str(
Expand All @@ -1342,7 +1345,7 @@ mod tests {
PayableAccount {
wallet: Wallet::new("0x4444444444444444444444444444444444444444"),
balance_wei: 10_000_000_100,
last_paid_timestamp: from_time_t(now - 86_300),
last_paid_timestamp: from_unix_timestamp(now - 86_300),
pending_payable_opt: None
},
]
Expand All @@ -1354,7 +1357,7 @@ mod tests {
//Accounts of balances smaller than one gwei don't qualify.
//Two accounts differ only in balance but not in the debt's age which allows to check doubled ordering,
//here by age and then by balance.
let now = now_time_t();
let now = current_unix_timestamp();
let main_test_setup = accounts_for_tests_of_top_records(now);
let subject = custom_query_test_body_for_payable(
"custom_query_in_top_records_mode_ordered_by_age",
Expand All @@ -1374,7 +1377,7 @@ mod tests {
PayableAccount {
wallet: Wallet::new("0x5555555555555555555555555555555555555555"),
balance_wei: 10_000_000_100,
last_paid_timestamp: from_time_t(now - 86_401),
last_paid_timestamp: from_unix_timestamp(now - 86_401),
pending_payable_opt: Some(PendingPayableId::new(
1,
H256::from_str(
Expand All @@ -1386,13 +1389,13 @@ mod tests {
PayableAccount {
wallet: Wallet::new("0x1111111111111111111111111111111111111111"),
balance_wei: 1_000_000_002,
last_paid_timestamp: from_time_t(now - 86_401),
last_paid_timestamp: from_unix_timestamp(now - 86_401),
pending_payable_opt: None
},
PayableAccount {
wallet: Wallet::new("0x4444444444444444444444444444444444444444"),
balance_wei: 10_000_000_100,
last_paid_timestamp: from_time_t(now - 86_300),
last_paid_timestamp: from_unix_timestamp(now - 86_300),
pending_payable_opt: None
},
]
Expand Down Expand Up @@ -1422,7 +1425,7 @@ mod tests {
fn custom_query_in_range_mode() {
//Two accounts differ only in debt's age but not balance which allows to check doubled ordering,
//by balance and then by age.
let now = now_time_t();
let now = current_unix_timestamp();
let main_setup = |conn: &dyn ConnectionWrapper, insert: InsertPayableHelperFn| {
insert(
conn,
Expand Down Expand Up @@ -1482,7 +1485,7 @@ mod tests {
max_age_s: 200000,
min_amount_gwei: 500_000_000,
max_amount_gwei: 35_000_000_000,
timestamp: from_time_t(now),
timestamp: from_unix_timestamp(now),
})
.unwrap();

Expand All @@ -1492,19 +1495,19 @@ mod tests {
PayableAccount {
wallet: Wallet::new("0x7777777777777777777777777777777777777777"),
balance_wei: gwei_to_wei(2_500_647_000_u32),
last_paid_timestamp: from_time_t(now - 80_333),
last_paid_timestamp: from_unix_timestamp(now - 80_333),
pending_payable_opt: None
},
PayableAccount {
wallet: Wallet::new("0x6666666666666666666666666666666666666666"),
balance_wei: gwei_to_wei(1_800_456_000_u32),
last_paid_timestamp: from_time_t(now - 100_401),
last_paid_timestamp: from_unix_timestamp(now - 100_401),
pending_payable_opt: None
},
PayableAccount {
wallet: Wallet::new("0x2222222222222222222222222222222222222222"),
balance_wei: gwei_to_wei(1_800_456_000_u32),
last_paid_timestamp: from_time_t(now - 55_120),
last_paid_timestamp: from_unix_timestamp(now - 55_120),
pending_payable_opt: Some(PendingPayableId::new(
1,
H256::from_str(
Expand All @@ -1519,7 +1522,7 @@ mod tests {

#[test]
fn range_query_does_not_display_values_from_below_1_gwei() {
let now = now_time_t();
let now = current_unix_timestamp();
let timestamp_1 = now - 11_001;
let timestamp_2 = now - 5000;
let main_setup = |conn: &dyn ConnectionWrapper, insert: InsertPayableHelperFn| {
Expand Down Expand Up @@ -1558,7 +1561,7 @@ mod tests {
vec![PayableAccount {
wallet: Wallet::new("0x2222222222222222222222222222222222222222"),
balance_wei: 30_000_300_000,
last_paid_timestamp: from_time_t(timestamp_2),
last_paid_timestamp: from_unix_timestamp(timestamp_2),
pending_payable_opt: None
},]
)
Expand All @@ -1570,7 +1573,7 @@ mod tests {
let conn = DbInitializerReal::default()
.initialize(&home_dir, DbInitializationConfig::test_default())
.unwrap();
let timestamp = utils::now_time_t();
let timestamp = utils::current_unix_timestamp();
insert_payable_record_fn(
&*conn,
"0x1111111111111111111111111111111111111111",
Expand Down
Loading
Loading