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

Fix Rosetta account creation fee reporting and improve testing #14945

Merged
merged 11 commits into from
Jan 25, 2024
38 changes: 32 additions & 6 deletions src/app/rosetta/lib/block.ml
Original file line number Diff line number Diff line change
Expand Up @@ -842,12 +842,21 @@ module Sql = struct
AND ai_receiver.id = ac.account_identifier_id
AND buc.status = 'applied'
AND buc.sequence_no =
(SELECT MIN(buc2.sequence_no)
FROM blocks_user_commands buc2
INNER JOIN user_commands uc2
ON buc2.user_command_id = uc2.id
AND uc2.receiver_id = u.receiver_iD
AND buc2.block_id = buc.block_id)
(SELECT LEAST(
(SELECT min(bic2.sequence_no)
FROM blocks_internal_commands bic2
INNER JOIN internal_commands ic2
ON bic2.internal_command_id = ic2.id
WHERE ic2.receiver_id = u.receiver_id
AND bic2.block_id = buc.block_id
AND bic2.status = 'applied'),
(SELECT min(buc2.sequence_no)
FROM blocks_user_commands buc2
INNER JOIN user_commands uc2
ON buc2.user_command_id = uc2.id
WHERE uc2.receiver_id = u.receiver_id
AND buc2.block_id = buc.block_id
AND buc2.status = 'applied')))
INNER JOIN tokens t
ON t.id = ai_receiver.token_id
WHERE buc.block_id = ?
Expand Down Expand Up @@ -897,6 +906,23 @@ module Sql = struct
ON ai.public_key_id = receiver_id
LEFT JOIN accounts_created ac
ON ac.account_identifier_id = ai.id
AND ac.block_id = bic.block_id
AND bic.sequence_no =
(SELECT LEAST(
(SELECT min(bic2.sequence_no)
FROM blocks_internal_commands bic2
INNER JOIN internal_commands ic2
ON bic2.internal_command_id = ic2.id
WHERE ic2.receiver_id = i.receiver_id
AND bic2.block_id = bic.block_id
AND bic2.status = 'applied'),
(SELECT min(buc2.sequence_no)
FROM blocks_user_commands buc2
INNER JOIN user_commands uc2
ON buc2.user_command_id = uc2.id
WHERE uc2.receiver_id = i.receiver_id
AND buc2.block_id = bic.block_id
AND buc2.status = 'applied')))
INNER JOIN tokens t
ON t.id = ai.token_id
WHERE bic.block_id = ?
Expand Down
10 changes: 9 additions & 1 deletion src/app/rosetta/lib/network.ml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ let sync_status_to_string = function
| `SYNCED ->
"Synced"

let is_synced = function
| `SYNCED -> true
| `BOOTSTRAP
| `CATCHUP
| `CONNECTING
| `LISTENING
| `OFFLINE -> false

module Get_version =
[%graphql
{|
Expand Down Expand Up @@ -239,7 +247,7 @@ module Status = struct
Some ((latest_node_block.protocolState).consensusState).blockHeight
; target_index= None
; stage= Some (sync_status_to_string res.syncStatus)
; synced = None
; synced = (Some (is_synced res.syncStatus))
} }
end

Expand Down
6 changes: 3 additions & 3 deletions src/app/rosetta/rosetta-cli-config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ is specified in the `config.json`, in `data` section (see the
example mentioned above). For example an end condition:
`"index": 50` will make `rosetta-cli to check first 50 blocks.

**IMPORTANT** as of version 0.8.2 of `rosetta-sdk-go`, rosetta-cli
**IMPORTANT** as of version 0.8.3 of `rosetta-sdk-go`, rosetta-cli
is unable to run the `mina.ros` file, which will only work with
[Mina Foundation's fork](https://github.com/MinaProtocol/rosetta-sdk-go/tree/pallas_signer_stake_delegation).
Therefore, whenever it is required to run the Construction API
tests against v.0.8.2 of `rosetta-sdk-go`, `mina-no-delegation-tests.ros`
tests against v.0.8.3 of `rosetta-sdk-go`, `mina-no-delegation-tests.ros`
config should be used for that instead of `mina.ros`, which is used
in the CI. `mina-no-delegation-tests.ros` should be deleted once
in the CI. In alternative, one can also use [our `rosetta-cli` fork](https://github.com/MinaProtocol/rosetta-cli) which is built against our fork of `rosetta-sdk-go`. `mina-no-delegation-tests.ros` should be deleted once
[PR #464](https://github.com/coinbase/rosetta-sdk-go/pull/464) to
`rosetta-sdk-go` is merged.
6 changes: 3 additions & 3 deletions src/app/rosetta/rosetta-cli-config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
"online_url": "http://localhost:PLACEHOLDER_ROSETTA_ONLINE_PORT",
"data_directory": "",
"http_timeout": 10,
"http_timeout": 300,
"max_retries": 5,
"retry_elapsed_time": 0,
"max_online_connections": 120,
Expand Down Expand Up @@ -47,8 +47,8 @@
"initial_balance_fetch_disabled": false,
"end_conditions": {
"create_account": 10,
"transfer_payment": 20,
"transfer_delegation": 5
"payment": 20,
"delegation": 5
}
},
"data": {
Expand Down
104 changes: 76 additions & 28 deletions src/app/rosetta/rosetta-cli-config/mina-no-delegation-test.ros
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// This is the version of the Construction API tests does not test
// stake delegation, which cannot be tested with rosetta-sdk-go as
// of v. 0.8.2.

// Workflow used to create new accounts
create_account(1){
create{
network = {"network":"debug", "blockchain":"mina"};
network = {
"network":"berkeley-ITN",
"blockchain":"mina"
};
key = generate_key({"curve_type": "pallas"});
account = derive({
"network_identifier": {{network}},
Expand All @@ -21,31 +20,32 @@ create_account(1){
}

// Workflow used to generate payment transactions
transfer(10){
transfer{
transfer.network = {"network":"debug", "blockchain":"mina"};
currency = {"symbol":"MINA", "decimals":9};
payment(10){
payment_dry_run{
payment_dry_run.network = {
"network":"berkeley-ITN",
"blockchain":"mina"
};

currency = {
"symbol":"MINA",
"decimals":9
};

max_fee = "4000000000"; // no less than 1 MINA + 1 MINA (account creation fee)
max_recipient_value = "100000000000"; // 100 MINA
min_required_value = {{max_recipient_value}} + {{max_fee}};

sender = find_balance({
"minimum_balance":{
"value": "20000000000",
"value": {{min_required_value}},
"currency": {{currency}}
}
});

// The fee must be at least the creation fee of the account if it
// did not exist before the transaction
max_fee = "4000000000";
min_fee = "2000000000";

// We limit the amount to genereate multiple transactions with the
// same prefunded account
available_amount = "6000000000";
recipient_amount = random_number({"minimum": "1", "maximum": {{max_recipient_value}}});
print_message({"recipient_amount":{{recipient_amount}}});

// Find recipient and construct operations
recipient_amount = random_number({"minimum": {{max_fee}}, "maximum": {{available_amount}}});
sender_amount = 0 - {{recipient_amount}};
fee = random_number({"minimum": {{min_fee}}, "maximum": {{max_fee}}});
minus_fee = 0 - {{fee}};
recipient = find_balance({
"not_account_identifier":[{{sender.account_identifier}}],
"minimum_balance":{
Expand All @@ -55,21 +55,68 @@ transfer(10){
"create_limit": 100,
"create_probability": 50
});
transfer.confirmation_depth = "1";

sender_amount = 0 - {{recipient_amount}};
sender_fee = 0 - {{max_fee}};

// The valid_until field must be provided explicitely until the
// default value is fixed
// See https://github.com/coinbase/rosetta-sdk-go/pull/457
transfer.preprocess_metadata={"valid_until": "4294967295"};
payment_dry_run.preprocess_metadata={"valid_until": "4294967295"};
payment_dry_run.confirmation_depth = "1";
payment_dry_run.dry_run = true;
payment_dry_run.operations = [
{
"operation_identifier":{"index":0},
"type":"fee_payment",
"account":{{sender.account_identifier}},
"amount":{
"value": {{sender_fee}},
"currency":{{currency}}
}
},
{
"operation_identifier":{"index":1},
"type":"payment_source_dec",
"account":{{sender.account_identifier}},
"amount":{
"value":{{sender_amount}},
"currency":{{currency}}
}
},
{
"operation_identifier":{"index":2},
"related_operations":[{"index":1}],
"type": "payment_receiver_inc",
"account":{{recipient.account_identifier}},
"amount":{
"value":{{recipient_amount}},
"currency":{{currency}}
}
}
];

print_message("done payment dry run");
},
payment{
suggested_fee = find_currency_amount({
"currency":{{currency}},
"amounts":{{payment_dry_run.suggested_fee}}
});
print_message({"suggested_fee":{{suggested_fee.value}}});

sender_fee = 0 - {{suggested_fee.value}};

// Operations for a payment transaction
transfer.operations = [
payment.preprocess_metadata={"valid_until": "4294967295"};
payment.network = {{payment_dry_run.network}};
payment.confirmation_depth = {{payment_dry_run.confirmation_depth}};
payment.operations = [
{
"operation_identifier":{"index":0},
"type":"fee_payment",
"account":{{sender.account_identifier}},
"amount":{
"value": {{minus_fee}},
"value": {{sender_fee}},
"currency":{{currency}}
}
},
Expand All @@ -84,6 +131,7 @@ transfer(10){
},
{
"operation_identifier":{"index":2},
"related_operations":[{"index":1}],
"type": "payment_receiver_inc",
"account":{{recipient.account_identifier}},
"amount":{
Expand Down
Loading
Loading