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

GH-711: Completion of fundamental Payment Adjuster and its peripheries #442

Open
wants to merge 199 commits into
base: master
Choose a base branch
from

Conversation

bertllll
Copy link
Contributor

No description provided.

Bert added 30 commits May 4, 2023 18:32
… tests for BlockchainInterfaceClandestine should be made first
@bertllll bertllll changed the title GH-711: Completion of the fundamental Payment Adjuster and its peripheries GH-711: Completion of fundamental Payment Adjuster and its peripheries May 2, 2024
}

impl Percentage {
pub fn new(num: u8) -> Self {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you'd like the approach of try_from here. https://doc.rust-lang.org/std/convert/trait.TryFrom.html


pub fn of<N>(&self, num: N) -> N
where
N: From<u8> + CheckedMul + CheckedAdd + CheckedDiv + PartialOrd + Integer + Debug + Copy,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create a generic boundary:

trait PercentageInteger: From<u8> + CheckedSub + CheckedMul + CheckedAdd + CheckedDiv + PartialOrd + Integer + Debug + Copy;

return zero;
}

let a = match N::from(self.per_cent).checked_mul(&num) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you'd like you can call this variable product.

Copy link
Collaborator

@utkarshg6 utkarshg6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Continue with masq_lib/src/percentage.rs:81

where
N: From<u8> + CheckedMul + CheckedAdd + CheckedDiv + PartialOrd + Integer + Debug + Copy,
{
self.of(num).checked_add(&num).unwrap_or_else(|| {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps you'd like to do it this way by creating one more variable.

let additional_fractional = self.of(num);
num.checked_add(additional_fractional).unwrap_or_else(|| { ... })

N: From<u8> + Div<Output = N> + Mul<Output = N>,
{
num / From::from(100) * N::from(self.per_cent)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a method to get percents bigger than one hundred, perhaps thousands, millions, etc. Internally, it'd simply use mod 100 to get how many times we should multiply or divide the input before we use the remainder as
Percentage::new(remainder) and the other methods to compute the absolute remainder to be added to the big counts done a step before.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a great idea. 👍

If you feel like, go ahead implement it.

Copy link
Collaborator

@utkarshg6 utkarshg6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look at the of function and then move forward to line 117.

.expect("should never happen by its principle")
}

fn should_be_rounded_down<N>(num: N) -> bool
Copy link
Collaborator

@utkarshg6 utkarshg6 May 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternate way:

fn round<N>(num: N, precision: u8) -> N {
    let divisor = N::from(10.pow(precision));
    let should_be_rounded = Percentage::should_be_rounded_down(num, divisor);
    let significant_digits_only = num.checked_div(divisor).expect("div failed");
    let significant_digits_only = match should_be_rounded {
       true => significant_digits_only.checked_add(N::from(1)).expect("addition failed"),
       false => significant_digits_only
    }
   
   significant_digits_only.checked_mul(divisor).expect("multiplication failed")
}
fn should_be_rounded_down<N>(num: N, divisor: N) -> bool {
   let least_significant_digits: N = mod_floor(num, divisor);
   let boundary = divisor.checked_div(N::from(2)).expect("div failed");
   least_significant_digits < boundary
}

None => return self.handle_upper_overflow(num),
};

if a < N::from(10) {
Copy link
Collaborator

@utkarshg6 utkarshg6 May 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps you can use the round() function that was written in the comment below, it's not perfect yet, but I know you can make it perfect. 😉

In case you don't feel there isn't enough time, you may prefer a shorter way.

N: From<u8> + Div<Output = N> + Mul<Output = N>,
{
num / From::from(100) * N::from(self.per_cent)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a great idea. 👍

If you feel like, go ahead implement it.

}

#[test]
fn add_percent_to_works() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps, a better idea (as mentioned by your marvellous mind), that we should use maybe the other strategy where we could have something like 700% of a number.

The constructor shouldn't be limited to 0..100 but to a bigger numbers (maybe u32::MAX). Just consider this limit wisely.

Copy link
Collaborator

@utkarshg6 utkarshg6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Continue reading the test_body() and then continue later from line 147.

@@ -0,0 +1,10 @@
# Copyright (c) 2019, MASQ (https://masq.ai) and/or its affiliates. All rights reserved.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The copyrights can be updated here to 2024.

// immediately. That's why some consideration has been made not to take out the passage with
// the intense startups of a bunch of Nodes, with that particular reason to fulfill the above
// depicted scenario, even though this test could be written more simply with the use of
// the `scans` command emitted from a UI, with a smaller PCU burden. (You may want to know that
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You want "CPU" instead of "PCU"

gwei_to_wei::<u128, _>(payment_thresholds.debt_threshold_gwei) + 456_789;
let owed_to_serving_node_3_minor =
gwei_to_wei::<u128, _>(payment_thresholds.debt_threshold_gwei) + 789_012;
let cons_node_initial_service_fee_balance_minor =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use consuming instead of cons.

gwei_to_wei::<u128, _>(payment_thresholds.debt_threshold_gwei) + 789_012;
let cons_node_initial_service_fee_balance_minor =
gwei_to_wei::<u128, _>(payment_thresholds.debt_threshold_gwei) * 4;
let exp_final_cons_node_service_fee_balance_minor = cons_node_initial_service_fee_balance_minor
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I sometimes use exp for exponent and you'd prefer it for expected. I'd like if you use expected to help my silly mind.

- (owed_to_serving_node_1_minor
+ owed_to_serving_node_2_minor
+ owed_to_serving_node_3_minor);
let test_global_config = TestInputsOutputsConfig {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This structure contains both preparatory as well as expected parameters. If you'd decouple them, it'll be better. 👍

serving_node_2_attributes: ServingNodeAttributes,
serving_node_3_attributes: ServingNodeAttributes,
_test_global_config: &TestInputsOutputsConfig| {
let serving_node_1 = cluster.start_named_real_node(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you use this as the closure's parameter: [ServingNodeAttributes; 3], then there would be less parameters in the closure.

serving_node_3_attributes.index,
serving_node_3_attributes.config,
);
for _ in 0..6 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You and I see a possibility of optimisation here:

  1. Total 9 Nodes were created, maybe we can get by with a lower number (3 + 3).
  2. I'm unsure whether it's the necessity of the test to provide three Node references to each extra Node (the one in loop) that you want to start.

config: NodeStartupConfig,
}

fn test_body<StimulateConsumingNodePayments, StartServingNodesAndLetThemPerformReceivablesCheck>(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only concern that I have here is the length of this function, which makes it difficult to identify the important stuff from less important items.

A personal preference is:

  • Using refactored functions
  • Structs in place of tuples (so that things are explicit)

Copy link
Collaborator

@utkarshg6 utkarshg6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Continue at verify_bill_payments: 825.

We want to discuss that the debts might not be old enough since we're using the now.

@@ -61,44 +719,81 @@ fn verify_bill_payment() {
contract_addr
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We maybe would like to improve this message:

Either the contract has been modified or Ganache is not accurately mimicing Ethereum.

);
let initial_transaction_fee_balance = global_config
.cons_node_initial_transaction_fee_balance_minor_opt
.unwrap_or(1_000_000_000_000_000_000);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The benefits I can think of are:

  1. In case we're using this value multiple times, we can reuse it
  2. It can make it easier to figure out the value.

We may create a new constant.

const ONE_ETH_IN_WEI = 1_000_000_000_000_000_000;

&blockchain_interface,
"99998043204000000000",
"472000000000000000000000000",
global_config
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use this variable here: initial_transaction_fee_balance

@@ -61,44 +719,81 @@ fn verify_bill_payment() {
contract_addr
);
let blockchain_interface = BlockchainInterfaceWeb3::new(http, event_loop_handle, cluster.chain);
assert_balances(
let (consuming_config, consuming_node_wallet) = build_config(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can pass the global_config to reduce the number of arguments in this fn.

};
let (consuming_config, _) =
build_config(&blockchain_server, &seed, payment_thresholds, deriv_path);

let (serving_node_1_config, serving_node_1_wallet) = build_config(
&blockchain_server,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's discovered that you can pass the url here instead. Also, you can use the NodeByRole enum to retrieve the derivation path.

You have this suggestion too that we can use the eprintln! inside the build_config function.

Another suggestion: You may pass an Enum value as an argument which decides whether eprintln! should be printed or not. You may. like to keep it in the global config.

enum PrintMode {
    DEBUG,
    OFF
}

Further Idea: You can make build_config a method of global config.

That way we'll only need to pass one argument to pull the config out.

let (serving_node_1_config, serving_node_1_wallet) = global_config.build_config(NodeByRole::ServNode1);

Consider new name for the above method, maybe : get_node_config_and_wallet.

);

let amount = 10 * payment_thresholds.permanent_debt_allowed_gwei as u128 * WEIS_IN_GWEI as u128;

let (consuming_node_name, consuming_node_index) = cluster.prepare_real_node(&consuming_config);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two functions that require renaming:

  1. do_prepare_for_docker_run
  2. The function that uses this function and named prepare.

You may like to change it to say, prepare_node_directories_for_docker.

You can incorporate the function that's on the next line and can make this function return 3 elements in the tuple.

@@ -107,35 +802,46 @@ fn verify_bill_payment() {
make_init_config(cluster.chain),
)
.unwrap();
let consuming_payable_dao = PayableDaoReal::new(consuming_node_connection);
let consuming_node_payable_dao = PayableDaoReal::new(consuming_node_connection);
open_all_file_permissions(consuming_node_path.clone().into());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code inside this function should be migrated to the function where we're preparing directories.

open_all_file_permissions(consuming_node_path.clone().into());
assert_eq!(
format!("{}", &contract_owner_wallet),
"0x5a4d5df91d0124dec73dbd112f82d6077ccab47d"
format!("{}", &consuming_node_wallet),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may prefer not to use the format!(), instead you may like to call the .address() function instead. But that'll give you H160. So, you may want to use .to_string() on it.

);
let now = SystemTime::now();
consuming_payable_dao
.more_money_payable(now, &serving_node_1_wallet, amount)
consuming_node_payable_dao
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can migrate these 3 setting up statements into a function which takes dao and global_config to create debts inside the Consuming Node's DB.

Copy link
Collaborator

@utkarshg6 utkarshg6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Continue at multinode_integration_tests/tests/verify_bill_payment.rs:975

);
assert_eq!(
format!("{}", &serving_node_3_wallet),
"0xb329c8b029a2d3d217e71bc4d188e8e1a4a8b924"
"0xb45a33ef3e3097f34c826369b74141ed268cdb5a"
);
let now = SystemTime::now();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enhancement: You mentioned that you'd like to provide a different way to expire the payables, instead of subtracting the time later, you'd like to do it here. It might be better to keep the code the way it is right now. Verify.

It would be better if we have this timestamp at the top of this function which will act as a reminder that Timestamps are critical to this test.

@@ -147,10 +853,13 @@ fn verify_bill_payment() {
.unwrap();
let serving_node_1_receivable_dao = ReceivableDaoReal::new(serving_node_1_connection);
serving_node_1_receivable_dao
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can have a similar function for receivables, just like payables as mentioned in the comment above. You're creating a new timestamp in this function. If you'd like to keep the same or different value, please add a constant number instead.

);

assert_balances(
expire_payables(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that we don't need these functions to expiring the payables and receivables and perhaps we can find an alternate way using the timestamp. Please investigate if it can be done in a more concise manner.

expire_receivables(serving_node_3_path.into());
assert_balances(&serving_node_1_wallet, &blockchain_interface, 0, 0);
assert_balances(&serving_node_2_wallet, &blockchain_interface, 0, 0);
assert_balances(&serving_node_3_wallet, &blockchain_interface, 0, 0);
let real_consuming_node =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might perfer to call it just consuming_node and if this name is taken prior to this line, prefer adding prepare or a similar word to the old one to differentiate it.


let now = Instant::now();
while !consuming_payable_dao.non_pending_payables().is_empty()
while !consuming_node_payable_dao.non_pending_payables().is_empty()
&& now.elapsed() < Duration::from_secs(10)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You maybe rename the now to say waiting_instant.

&serving_node_3_name,
serving_node_3_index,
serving_node_3_config,
let serving_node_1_attributes = ServingNodeAttributes {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can create a constructor for ServingNodeAttributes that takes these 3 values. Maybe you'd like to call it something along the lines: NodeDockerConfig.

.build(),
);
}

test_utils::wait_for(Some(1000), Some(15000), || {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can maybe have a function here, which we can reuse for these following cases:

fn wait_for_balances(node_dao, expected_value) {
    test_utils::wait_for(Some(1000), Some(15000), || {
            if let Some(status) = node_dao.account_status(&consuming_node_wallet) {
            status.balance_wei
                == i128::try_from(expected_value)
                .unwrap()
        } else {
            false
        }
    });
}

Later we can use it as:

wait_for_balances(
    serving_node_1_receivable_dao, 
     global_config.debt_size(NodeByRole::ServNode1) - global_config.exp_final_service_fee_balance_serv_node_1_minor
)

Note: If you'd like you can make it a method inside global_config.

status.balance_wei
== i128::try_from(
global_config.debt_size(NodeByRole::ServNode1)
- global_config.exp_final_service_fee_balance_serv_node_1_minor,
Copy link
Collaborator

@utkarshg6 utkarshg6 May 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should investigate this condition further. Maybe we'd just like to check against the final value instead of subtracting it.

It would be better if we compare it with the expected value instead of the subtracted outcome.

Copy link
Collaborator

@utkarshg6 utkarshg6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Continue from multinode_integration_tests/tests/verify_bill_payment.rs:147

global_config.debt_size(NodeByRole::ServNode3)
- global_config.exp_final_service_fee_balance_serv_node_3_minor,
)
.unwrap()
} else {
false
}
});
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you'd like let's migrate this to a new place, maybe inside a new folder or a file named multinode_integration_tests/src/web3_utils.rs

}

fn deploy_smart_contract(wallet: &Wallet, web3: &Web3<Http>, chain: Chain) -> Address {
let data = "608060405234801561001057600080fd5b5060038054600160a060020a031916331790819055604051600160a060020a0391909116906000907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908290a3610080336b01866de34549d620d8000000640100000000610b9461008582021704565b610156565b600160a060020a038216151561009a57600080fd5b6002546100b490826401000000006109a461013d82021704565b600255600160a060020a0382166000908152602081905260409020546100e790826401000000006109a461013d82021704565b600160a060020a0383166000818152602081815260408083209490945583518581529351929391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a35050565b60008282018381101561014f57600080fd5b9392505050565b610c6a806101656000396000f3006080604052600436106100fb5763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166306fdde038114610100578063095ea7b31461018a57806318160ddd146101c257806323b872dd146101e95780632ff2e9dc14610213578063313ce56714610228578063395093511461025357806342966c681461027757806370a0823114610291578063715018a6146102b257806379cc6790146102c75780638da5cb5b146102eb5780638f32d59b1461031c57806395d89b4114610331578063a457c2d714610346578063a9059cbb1461036a578063dd62ed3e1461038e578063f2fde38b146103b5575b600080fd5b34801561010c57600080fd5b506101156103d6565b6040805160208082528351818301528351919283929083019185019080838360005b8381101561014f578181015183820152602001610137565b50505050905090810190601f16801561017c5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561019657600080fd5b506101ae600160a060020a0360043516602435610436565b604080519115158252519081900360200190f35b3480156101ce57600080fd5b506101d7610516565b60408051918252519081900360200190f35b3480156101f557600080fd5b506101ae600160a060020a036004358116906024351660443561051c565b34801561021f57600080fd5b506101d76105b9565b34801561023457600080fd5b5061023d6105c9565b6040805160ff9092168252519081900360200190f35b34801561025f57600080fd5b506101ae600160a060020a03600435166024356105ce565b34801561028357600080fd5b5061028f60043561067e565b005b34801561029d57600080fd5b506101d7600160a060020a036004351661068b565b3480156102be57600080fd5b5061028f6106a6565b3480156102d357600080fd5b5061028f600160a060020a0360043516602435610710565b3480156102f757600080fd5b5061030061071e565b60408051600160a060020a039092168252519081900360200190f35b34801561032857600080fd5b506101ae61072d565b34801561033d57600080fd5b5061011561073e565b34801561035257600080fd5b506101ae600160a060020a0360043516602435610775565b34801561037657600080fd5b506101ae600160a060020a03600435166024356107c0565b34801561039a57600080fd5b506101d7600160a060020a03600435811690602435166107d6565b3480156103c157600080fd5b5061028f600160a060020a0360043516610801565b606060405190810160405280602481526020017f486f7420746865206e657720746f6b656e20796f75277265206c6f6f6b696e6781526020017f20666f720000000000000000000000000000000000000000000000000000000081525081565b600081158061044c575061044a33846107d6565b155b151561050557604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152604160248201527f55736520696e637265617365417070726f76616c206f7220646563726561736560448201527f417070726f76616c20746f2070726576656e7420646f75626c652d7370656e6460648201527f2e00000000000000000000000000000000000000000000000000000000000000608482015290519081900360a40190fd5b61050f838361081d565b9392505050565b60025490565b600160a060020a038316600090815260016020908152604080832033845290915281205482111561054c57600080fd5b600160a060020a0384166000908152600160209081526040808320338452909152902054610580908363ffffffff61089b16565b600160a060020a03851660009081526001602090815260408083203384529091529020556105af8484846108b2565b5060019392505050565b6b01866de34549d620d800000081565b601281565b6000600160a060020a03831615156105e557600080fd5b336000908152600160209081526040808320600160a060020a0387168452909152902054610619908363ffffffff6109a416565b336000818152600160209081526040808320600160a060020a0389168085529083529281902085905580519485525191937f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929081900390910190a350600192915050565b61068833826109b6565b50565b600160a060020a031660009081526020819052604090205490565b6106ae61072d565b15156106b957600080fd5b600354604051600091600160a060020a0316907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a36003805473ffffffffffffffffffffffffffffffffffffffff19169055565b61071a8282610a84565b5050565b600354600160a060020a031690565b600354600160a060020a0316331490565b60408051808201909152600381527f484f540000000000000000000000000000000000000000000000000000000000602082015281565b6000600160a060020a038316151561078c57600080fd5b336000908152600160209081526040808320600160a060020a0387168452909152902054610619908363ffffffff61089b16565b60006107cd3384846108b2565b50600192915050565b600160a060020a03918216600090815260016020908152604080832093909416825291909152205490565b61080961072d565b151561081457600080fd5b61068881610b16565b6000600160a060020a038316151561083457600080fd5b336000818152600160209081526040808320600160a060020a03881680855290835292819020869055805186815290519293927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929181900390910190a350600192915050565b600080838311156108ab57600080fd5b5050900390565b600160a060020a0383166000908152602081905260409020548111156108d757600080fd5b600160a060020a03821615156108ec57600080fd5b600160a060020a038316600090815260208190526040902054610915908263ffffffff61089b16565b600160a060020a03808516600090815260208190526040808220939093559084168152205461094a908263ffffffff6109a416565b600160a060020a038084166000818152602081815260409182902094909455805185815290519193928716927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3505050565b60008282018381101561050f57600080fd5b600160a060020a03821615156109cb57600080fd5b600160a060020a0382166000908152602081905260409020548111156109f057600080fd5b600254610a03908263ffffffff61089b16565b600255600160a060020a038216600090815260208190526040902054610a2f908263ffffffff61089b16565b600160a060020a038316600081815260208181526040808320949094558351858152935191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929081900390910190a35050565b600160a060020a0382166000908152600160209081526040808320338452909152902054811115610ab457600080fd5b600160a060020a0382166000908152600160209081526040808320338452909152902054610ae8908263ffffffff61089b16565b600160a060020a038316600090815260016020908152604080832033845290915290205561071a82826109b6565b600160a060020a0381161515610b2b57600080fd5b600354604051600160a060020a038084169216907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a36003805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0392909216919091179055565b600160a060020a0382161515610ba957600080fd5b600254610bbc908263ffffffff6109a416565b600255600160a060020a038216600090815260208190526040902054610be8908263ffffffff6109a416565b600160a060020a0383166000818152602081815260408083209490945583518581529351929391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a350505600a165627a7a72305820d4ad56dfe541fec48c3ecb02cebad565a998dfca7774c0c4f4b1f4a8e2363a590029".from_hex::<Vec<u8>>().unwrap();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can put this in a txt file and load it from there.

"{}",
node_wallet.clone()
)));
let cfg_to_build = if let Some(port) = port_opt {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's migrate it to a different function instead:

configure_optional_values(cfg_to_build, value_opt)

Copy link
Collaborator

@utkarshg6 utkarshg6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

multinode_integration_tests/tests/verify_bill_payment.rs:178

use rustc_hex::{FromHex, ToHex};
use std::convert::TryFrom;
use std::path::{Path, PathBuf};
use std::time::{Duration, Instant, SystemTime};
use std::{thread, u128};
use tiny_hderive::bip32::ExtendedPrivKey;
use web3::transports::Http;
use web3::types::{Address, Bytes, TransactionParameters};
use web3::types::{Address, Bytes, SignedTransaction, TransactionParameters, TransactionRequest};
use web3::Web3;

#[test]
fn verify_bill_payment() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's give it a different name. This is what we came up during our session: full_payments_were_processed_for_sufficient_balances

let owed_to_serv_node_3_minor =
gwei_to_wei::<u128, _>(payment_thresholds.debt_threshold_gwei + 60_000_000);
// Assuming all Nodes rely on the same set of payment thresholds
let cons_node_initial_service_fee_balance_minor = (owed_to_serv_node_1_minor
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you'd like to add a comment mentioning that the biggest debt (Serving Node 3) will be dropped since the balance is insufficient to fulfill the needs of lower debt nodes (Serving Node 1 and Node 2). Also, you maybe prefer creating an extra variable too for more clarity in the computation steps.

let enough_balance_for_serving_node_1_and_2 = owed_to_serv_node_1_minor + owed_to_serv_node_2_minor;
let cons_node_initial_service_fee_balance_minor = enough_balance_for_serving_node_1_and_2 - gwei_to_wei::<u128, u64>(2_345_678);

Copy link
Collaborator

@utkarshg6 utkarshg6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Continue at multinode_integration_tests/tests/verify_bill_payment.rs:310

let agreed_transaction_fee_unit_price_major = 60;
let transaction_fee_needed_to_pay_for_one_payment_major = {
// We will need less but this should be accurate enough
let txn_data_with_maximized_cost = [0xff; 68];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a comment explaining why such values were chosen. You explained it to me, I understand them now (a glimpse) but I'm unsure if everyone else will.

So, a comment will be good. 👍

transaction_fee_needed_to_pay_for_one_payment_major
);
let cons_node_transaction_fee_balance_minor =
2 * gwei_to_wei::<u128, u64>(transaction_fee_needed_to_pay_for_one_payment_major);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this'll make it clearer.

const AFFORDABLE_PAYMENTS_COUNT = 2;
let transaction_fee_needed_to_pay_for_one_payment_minor = gwei_to_wei::<u128, u64>(transaction_fee_needed_to_pay_for_one_payment_major);
let cons_node_transaction_fee_balance_minor = payments_count * transaction_fee_needed_to_pay_for_one_payment_minor;

}),
// Should be enough only for two payments, the least significant one will fall out
cons_node_initial_transaction_fee_balance_minor_opt: Some(
cons_node_transaction_fee_balance_minor + 1,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also think it's safe to use cons_node_transaction_fee_balance_minor without adding any value.

balance_minor: owed_to_serv_node_2_minor,
age_s: payment_thresholds.maturity_threshold_sec + 100_000,
},
// This account will be the least significant and therefore eliminated
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's introduce this: therefore eliminated due to tx fee

cons_node_transaction_fee_agreed_unit_price_opt: Some(
agreed_transaction_fee_unit_price_major,
),
// It seems like the ganache server sucked up quite less than those 55_000 units of gas??
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you'd prefer to improve the comment.

The remainder balance expected by ganache after txns were successful

Maybe something different according to your understanding.

|_cluster: &mut MASQNodeCluster,
real_consuming_node: &MASQRealNode,
_global_test_config: &TestInputsOutputsConfig| {
process_scan_request_to_node(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It appears that we maybe manage to work with 1 closure instead of 2. Maybe there is some other reason why you decided to keep both of them, please investigate.

serving_node_2_attributes: ServingNodeAttributes,
serving_node_3_attributes: ServingNodeAttributes,
test_global_config: &TestInputsOutputsConfig|
-> (MASQRealNode, MASQRealNode, MASQRealNode) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: If the deconstruction of returned value is not essential, then maybe you'd limit the length using an array.

-> [MASQRealNode; 3]
let iter = 1..3;
let (x, y) = iter.collect_tuple().unwrap(); // yeah!

Copy link
Collaborator

@utkarshg6 utkarshg6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

multinode_integration_tests/tests/verify_bill_payment.rs:444

);
}

fn make_init_config(chain: Chain) -> DbInitializationConfig {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A suggestion that you wanted me to add:

make_init_config() -> make_db_init_config()


fn deploy_smart_contract(wallet: &Wallet, web3: &Web3<Http>, chain: Chain) -> Address {
let data = "608060405234801561001057600080fd5b5060038054600160a060020a031916331790819055604051600160a060020a0391909116906000907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908290a3610080336b01866de34549d620d8000000640100000000610b9461008582021704565b610156565b600160a060020a038216151561009a57600080fd5b6002546100b490826401000000006109a461013d82021704565b600255600160a060020a0382166000908152602081905260409020546100e790826401000000006109a461013d82021704565b600160a060020a0383166000818152602081815260408083209490945583518581529351929391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a35050565b60008282018381101561014f57600080fd5b9392505050565b610c6a806101656000396000f3006080604052600436106100fb5763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166306fdde038114610100578063095ea7b31461018a57806318160ddd146101c257806323b872dd146101e95780632ff2e9dc14610213578063313ce56714610228578063395093511461025357806342966c681461027757806370a0823114610291578063715018a6146102b257806379cc6790146102c75780638da5cb5b146102eb5780638f32d59b1461031c57806395d89b4114610331578063a457c2d714610346578063a9059cbb1461036a578063dd62ed3e1461038e578063f2fde38b146103b5575b600080fd5b34801561010c57600080fd5b506101156103d6565b6040805160208082528351818301528351919283929083019185019080838360005b8381101561014f578181015183820152602001610137565b50505050905090810190601f16801561017c5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561019657600080fd5b506101ae600160a060020a0360043516602435610436565b604080519115158252519081900360200190f35b3480156101ce57600080fd5b506101d7610516565b60408051918252519081900360200190f35b3480156101f557600080fd5b506101ae600160a060020a036004358116906024351660443561051c565b34801561021f57600080fd5b506101d76105b9565b34801561023457600080fd5b5061023d6105c9565b6040805160ff9092168252519081900360200190f35b34801561025f57600080fd5b506101ae600160a060020a03600435166024356105ce565b34801561028357600080fd5b5061028f60043561067e565b005b34801561029d57600080fd5b506101d7600160a060020a036004351661068b565b3480156102be57600080fd5b5061028f6106a6565b3480156102d357600080fd5b5061028f600160a060020a0360043516602435610710565b3480156102f757600080fd5b5061030061071e565b60408051600160a060020a039092168252519081900360200190f35b34801561032857600080fd5b506101ae61072d565b34801561033d57600080fd5b5061011561073e565b34801561035257600080fd5b506101ae600160a060020a0360043516602435610775565b34801561037657600080fd5b506101ae600160a060020a03600435166024356107c0565b34801561039a57600080fd5b506101d7600160a060020a03600435811690602435166107d6565b3480156103c157600080fd5b5061028f600160a060020a0360043516610801565b606060405190810160405280602481526020017f486f7420746865206e657720746f6b656e20796f75277265206c6f6f6b696e6781526020017f20666f720000000000000000000000000000000000000000000000000000000081525081565b600081158061044c575061044a33846107d6565b155b151561050557604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152604160248201527f55736520696e637265617365417070726f76616c206f7220646563726561736560448201527f417070726f76616c20746f2070726576656e7420646f75626c652d7370656e6460648201527f2e00000000000000000000000000000000000000000000000000000000000000608482015290519081900360a40190fd5b61050f838361081d565b9392505050565b60025490565b600160a060020a038316600090815260016020908152604080832033845290915281205482111561054c57600080fd5b600160a060020a0384166000908152600160209081526040808320338452909152902054610580908363ffffffff61089b16565b600160a060020a03851660009081526001602090815260408083203384529091529020556105af8484846108b2565b5060019392505050565b6b01866de34549d620d800000081565b601281565b6000600160a060020a03831615156105e557600080fd5b336000908152600160209081526040808320600160a060020a0387168452909152902054610619908363ffffffff6109a416565b336000818152600160209081526040808320600160a060020a0389168085529083529281902085905580519485525191937f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929081900390910190a350600192915050565b61068833826109b6565b50565b600160a060020a031660009081526020819052604090205490565b6106ae61072d565b15156106b957600080fd5b600354604051600091600160a060020a0316907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a36003805473ffffffffffffffffffffffffffffffffffffffff19169055565b61071a8282610a84565b5050565b600354600160a060020a031690565b600354600160a060020a0316331490565b60408051808201909152600381527f484f540000000000000000000000000000000000000000000000000000000000602082015281565b6000600160a060020a038316151561078c57600080fd5b336000908152600160209081526040808320600160a060020a0387168452909152902054610619908363ffffffff61089b16565b60006107cd3384846108b2565b50600192915050565b600160a060020a03918216600090815260016020908152604080832093909416825291909152205490565b61080961072d565b151561081457600080fd5b61068881610b16565b6000600160a060020a038316151561083457600080fd5b336000818152600160209081526040808320600160a060020a03881680855290835292819020869055805186815290519293927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929181900390910190a350600192915050565b600080838311156108ab57600080fd5b5050900390565b600160a060020a0383166000908152602081905260409020548111156108d757600080fd5b600160a060020a03821615156108ec57600080fd5b600160a060020a038316600090815260208190526040902054610915908263ffffffff61089b16565b600160a060020a03808516600090815260208190526040808220939093559084168152205461094a908263ffffffff6109a416565b600160a060020a038084166000818152602081815260409182902094909455805185815290519193928716927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3505050565b60008282018381101561050f57600080fd5b600160a060020a03821615156109cb57600080fd5b600160a060020a0382166000908152602081905260409020548111156109f057600080fd5b600254610a03908263ffffffff61089b16565b600255600160a060020a038216600090815260208190526040902054610a2f908263ffffffff61089b16565b600160a060020a038316600081815260208181526040808320949094558351858152935191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929081900390910190a35050565b600160a060020a0382166000908152600160209081526040808320338452909152902054811115610ab457600080fd5b600160a060020a0382166000908152600160209081526040808320338452909152902054610ae8908263ffffffff61089b16565b600160a060020a038316600090815260016020908152604080832033845290915290205561071a82826109b6565b600160a060020a0381161515610b2b57600080fd5b600354604051600160a060020a038084169216907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a36003805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0392909216919091179055565b600160a060020a0382161515610ba957600080fd5b600254610bbc908263ffffffff6109a416565b600255600160a060020a038216600090815260208190526040902054610be8908263ffffffff6109a416565b600160a060020a0383166000818152602081815260408083209490945583518581529351929391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a350505600a165627a7a72305820d4ad56dfe541fec48c3ecb02cebad565a998dfca7774c0c4f4b1f4a8e2363a590029".from_hex::<Vec<u8>>().unwrap();
let gas_price = 50_000_000_000_u64;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion from Bert to Bert: Either change the name to gas_price_in_wei or provide it in gwei (since it's the standard), and later convert it into the desired unit.

By me 😉: At any path you decide, I'd still like the unit in the variable name.

chain: Chain,
) {
let data = transaction_data_web3(to_wallet, amount_minor);
let gas_price = 150_000_000_000_u64;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you'd prefer to format it this way and maybe at other places.

let gas_price_in_wei = U256::try_from(150 * 1_000_000_000);

}
}

fn sign_transaction(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a function with a similar name in Node. So that we don't confuse one with another, can we pick a different name for this one? 🤔

.expect("transaction preparation failed")
}

fn transfer_transaction_fee_amount_to_address(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can merge the functions transfer_transaction_fee_amount_to_address and transfer_service_fee_amount_to_address inside a single function called transfer_amount.

It should take the from and to in the form of Address instead of being a wallet. That way you can either pick a wallet address or contract address.

I also checked regarding the unlock() method. It's weird that you need in one and not the other even though you need to transfer money in both of these functions. Upon looking further, it's safe to use unlock() for both cases since this is not the production code, so I think you can merge them accordingly.

Copy link
Collaborator

@utkarshg6 utkarshg6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Continue at node/src/accountant/mod.rs:1381

let phrase = "timber cage wide hawk phone shaft pattern movie army dizzy hen tackle lamp absent write kind term toddler sphere ripple idle dragon curious hold";
let mnemonic = Mnemonic::from_phrase(phrase, Language::English).unwrap();
let seed = Seed::new(&mnemonic, "");
seed
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The phrase would be better stored in a constant at the top of the most relevant file.

Also, I think you can directly return the seed (instead of creating a variable).

payment_thresholds: PaymentThresholds,
transaction_fee_agreed_price_per_unit_opt: Option<u64>,
wallet_derivation_path: String,
port_opt: Option<u16>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's rename port_opt -> ui_port_opt. Maybe transaction_fee_agreed_price_per_unit_opt -> gas_price_opt, you might need to change it at multiple places, so please rename it at your convenience.

(config, node_wallet)
}

fn expire_payables(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you want to use it differently, instead of expiring it at a later stage, you can configure using an older timestamp.

// Specify number of wei this account should possess at its initialisation.
// The consuming node gets the full balance of the contract owner if left as None.
// Cannot ever get more than what the "owner" has.
cons_node_initial_transaction_fee_balance_minor_opt: Option<u128>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of being an Opt, we can supply the Default value, resulting in this field becoming a u128 instead of Option<u128>.

It would be better if cons_node_transaction_fee_agreed_unit_price_opt doesn't have the Opt either.

This struct can be implemented using the BuilderPattern. I think it might be unnecessary work, so decide wisely.

owed_to_serving_node_3: AccountedDebt,
}

struct AccountedDebt {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe prefer Debt instead of AccountedDebt.

ServNode1,
ServNode2,
ServNode3,
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't know yet if it's a good idea, so it's just an idea:

Let's store the UI Port and Debt Size inside the enum.

.threshold_interval_sec over 10^9 would mean continuing to declare debts delinquent after
more than 31 years.
These restrictions do not seem overly strict for having .permanent_debt_allowed greater
than or equal to .debt_threshold_gwei would not make any sense and setting
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the reasoning for the two conditions ("greater than" and "equal to") to improve the quality of this documentation.


impl QualifiedPayableAccount {
pub fn new(
qualified_as: PayableAccount,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You want it to be bare_account instead due to consistency.

Ok(Either::Left(finalized_msg)) => finalized_msg,
Ok(Either::Right(unaccepted_msg)) => {
Some(Either::Left(complete_msg)) => Some(complete_msg),
Some(Either::Right(unaccepted_msg)) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit concerning to me that this combination of match statement and the possibility of the perform_payment_adjustment can return an Option<T>.

This opens up a lot of cases, and we would have to maintain all those cases for the lifetime of this code.

My assumption was that we need to take care of the adjustment in a single step, and that way it'll just return a Result<>. On the other hand there was the concern that if we do that we'll have to manage the Actor messages between Neighbourhood with the PaymentAdjuster. This concern balances out and keeps us in dilemma what should be the right step.

Since, I had a lack of info at the time of writing this message, please forgive me if this comment seems undesirable, and I'd appreciate if by any chance the comment seems reasonable, please investigate.

Copy link
Collaborator

@utkarshg6 utkarshg6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Continue at node/src/accountant/mod.rs:1575

// all that is mocked in this test
// the numbers for balances don't do real math, they need not match either the condition for
// the payment adjustment or the actual values that come from the payable size reducing
// algorithm: all that is mocked in this test
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'd like to get rid of this comment.

}

#[test]
fn received_qualified_payables_exceeding_our_masq_balance_are_adjusted_before_forwarded_to_blockchain_bridge(
) {
// the numbers for balances don't do real math, they need not to match either the condition for
// the numbers for balances don't do real math, they need not match either the condition for
// the payment adjustment or the actual values that come from the payable size reducing algorithm;
// all that is mocked in this test
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You wanted to improve it. I wasn't able to hear properly what you mean when you were trying to explain it to me. So, it's up to you if you'd like to improvise this comment.

Copy link
Collaborator

@utkarshg6 utkarshg6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

node/src/accountant/mod.rs:1680

make_payable_account(111_111),
1234567,
CreditorThresholds::new(1111111),
);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'd like to keep the provided values in the same unit. Prefer creating payable account using the utility function, then change the numbers to the unit that's used by the later two arguments.

Copy link
Collaborator

@utkarshg6 utkarshg6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Continue at node/src/accountant/payment_adjuster/adjustment_runners.rs

}

#[test]
fn payment_adjuster_throws_out_an_error_from_the_insolvency_check() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to add the stage details, so let's rename this to payment_adjuster_throws_out_an_error_during_stage_one_the_insolvency_check

}

#[test]
fn payment_adjuster_throws_out_an_error_meaning_entry_check_passed_but_adjustment_went_wrong() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also for this one:

payment_adjuster_throws_out_an_error_during_stage_two_adjustment_went_wrong

test_use_of_the_same_logger(&logger_clone, test_name)
}

fn test_handling_payment_adjuster_error(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'd like to change the name of the fn:

test_payment_adjuster_error_during_different_stages

subject.logger = Logger::new(test_name);
subject.scanners.payable = Box::new(payable_scanner);
let scan_started_at = SystemTime::now();
subject.scanners.payable.mark_as_started(scan_started_at);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You suggested to inline this.

number_of_accounts: 1,
transaction_fee_opt: Some(TransactionFeeImmoderateInsufficiency {
per_transaction_requirement_minor: 60 * 55_000,
cw_transaction_fee_balance_minor: gwei_to_wei(123_u64),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use gwei_to_wei in both these cases. It'll change the logs, so please take care of that.

log_handler
.exists_log_containing(&format!("INFO: {test_name}: The Payables scan ended in"));
log_handler.exists_log_containing(&format!(
"ERROR: {test_name}: Payable scanner could not finish. If matured payables stay untreated \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error should be dynamic and specific to the process, so that the logs printed before could be precise and repetition could be avoided.

Note: In case you've discovered a new solution then please write a new card for it. The work should not be included in this card.

subject.handle_payable_payment_setup(msg);

// Test didn't blow up while the subject was unbound to other actors
// therefore we didn't attempt to send the NodeUiMessage
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make this comment say:

// No NodeUiMessage was sent because there's no `response_skeleton`, it is evident by the fact that the test didn't blow up even though UIGateway is unbound

let (blockchain_bridge, _, blockchain_bridge_recording_arc) = make_recorder();
let now = SystemTime::now();
let payment_thresholds = PaymentThresholds::default();
let (qualified_payables, _, all_non_pending_payables) =
make_payables(now, &payment_thresholds);
make_unqualified_and_qualified_payables(now, &payment_thresholds);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's switch the order, make_qualified_and_unqualified_qualified_payables.

123,
)]),
protected_qualified_payables: protect_qualified_payables_in_test(vec![
make_non_guaranteed_qualified_payable(123),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's call it make_meaningless_qualified_payable. Remove the guaranteed from the other function and call it make_qualified_payable.

Suggestion by @bertllll

&DEFAULT_PAYMENT_THRESHOLDS,
now,
);
let pending_payable_scan_interval = 200; // Should be slightly less than 1/5 of the time until shutting the system
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't add the comment at the main line, so I'll add here
Screenshot 2024-07-12 at 3 06 42 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants