-
Notifications
You must be signed in to change notification settings - Fork 529
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
[rampup] Stop txn/network after slot feature #15000
Merged
Merged
Changes from 52 commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
11dc67b
Add slot_tx_end to compile config
joaosreis 7aefd8a
Create CLI flag. Add config to daemon config
joaosreis b273c44
Create block after stop slot using empty staged ledger diff
joaosreis ef37faf
Split CLI flag into enable/disable
joaosreis 7cd90d5
Add stop tx feature to validator
joaosreis 6be8cd7
Add stop slot feature to mina commands
joaosreis c638cf0
Add slot_chain_end to compile config
joaosreis f13a7a4
Update slot transaction and chain end flags in CLI
joaosreis 5aaba0a
Convert slot numbers to global slot type
joaosreis fabb4c9
Move txn slot check from mina_commands to graphql
joaosreis d9cdec8
Add SlotTxEndTest to test suite
joaosreis d2f3649
Add slot_tx_end and slot_chain_end definitions to
joaosreis 737b567
Removed one BP
joaosreis c08d084
Fix stop tx slot comparison
joaosreis 07d6076
Add missing slot_chain_end features
joaosreis 4628a04
Better test structure
joaosreis cdd6a70
Change build configs
joaosreis 840ea35
Remove CLI configuration flags. Use compile config directly.
joaosreis 2560a66
Adjustments to block production and validation. Add notifications
joaosreis 21ce836
Add slot_chain_end tests and other fixes to integration test
joaosreis da70971
Revert uneeded changes
joaosreis 1f3b8bc
Run test even when slot params are not set (validate usual behaviour)
joaosreis a440364
Merge remote-tracking branch 'origin/compatible' into joaosreis/hf-st…
joaosreis 0b70f8a
Reformat slot_end_test.ml
joaosreis da03efb
Move log slot_*_end message logic to outer BP run function
joaosreis 5887673
Don't run test if neither slot_*_end params are set
joaosreis 7938ca6
Use genesis timestamp to compute test end timestamp
joaosreis ce59ea4
Allow overriding slot_*_end with runtime config
joaosreis 697b9af
Reject transactions at transaction pool level
joaosreis 77fc86f
Fix missing versioned type update
joaosreis dc8ca49
Remove unnecessary changes
joaosreis 2073d43
Merge branch 'compatible' into joaosreis/hf-stop-txn-after-slot-compa…
joaosreis 8897d8b
Add new txn pool test case
joaosreis e1d5168
Flatten logic
joaosreis 9f75c63
Merge remote-tracking branch 'origin/compatible' into joaosreis/hf-st…
joaosreis 8f19650
Revert format changes
joaosreis c9c86fa
Merge branch 'compatible' into joaosreis/hf-stop-txn-after-slot-compa…
joaosreis cb1c7ec
Merge branch 'compatible' into joaosreis/hf-stop-txn-after-slot-compa…
georgeee bf49d4a
Merge remote-tracking branch 'origin/joaosreis/hf-stop-txn-after-slot…
joaosreis dd4d162
Revert slot_end_test changes
joaosreis 8fa750e
Reformat
joaosreis e898823
Call unnamed parameter last
joaosreis a40997b
Merge branch 'rampup' into joaosreis/hf-stop-txn-after-slot-rampup
georgeee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Usage: ./scripts/prepare-test-ledger.sh <BP key 1> <BP key 2> ... <BP key n> | ||
|
||
# Number of keys in ledger that won't be re-delegated | ||
NUM_GHOST_KEYS=${NUM_GHOST_KEYS:-0} | ||
KEY_BALANCE=100000 | ||
|
||
echo "Script assumes mainnet's start was at epoch 0 on 17th March 2021, if it's not the case, update the script please" >&2 | ||
|
||
if [[ $# -eq 0 ]]; then | ||
echo "Usage: ./scripts/prepare-test-ledger.sh <BP key 1> <BP key 2> ... <BP key n>" >&2 | ||
exit 1 | ||
fi | ||
|
||
num_keys=$# | ||
num_keys_and_ghost=$((num_keys + NUM_GHOST_KEYS)) | ||
|
||
now=$(date +%s) | ||
mainnet_start=$(date --date='2021-03-17 00:00:00' -u +%s) | ||
epoch_now=$(( (now-mainnet_start)/7140/180 )) | ||
|
||
ledger_file="$epoch_now.json" | ||
|
||
echo "Current epoch: $epoch_now" >&2 | ||
|
||
if [[ ! -f "$ledger_file" ]]; then | ||
ledgers_url="https://storage.googleapis.com/storage/v1/b/mina-staking-ledgers/o?maxResults=1&prefix=staking-$epoch_now" | ||
ledger_url=$(curl "$ledgers_url" | jq -r .items[0].mediaLink) | ||
|
||
wget -O $ledger_file "$ledger_url" | ||
fi | ||
|
||
keys_="" | ||
for key in "$@"; do | ||
keys_="\"$key\",$keys_" | ||
done | ||
keys_="${keys_:0:-1}" | ||
|
||
# jq filter to exclude block PKs from the ledger | ||
pre_filter="[.[] | select(.pk | IN($keys_) | not)]" | ||
|
||
########################################################## | ||
# Calculate and print approximate new balances | ||
########################################################## | ||
|
||
num_accounts=$(<$ledger_file jq "$pre_filter | length") | ||
total_balance=$(<$ledger_file jq "$pre_filter | [.[].balance | tonumber] | add | round") | ||
new_total_balance=$((total_balance+num_keys*KEY_BALANCE)) | ||
echo "Total accounts: $num_accounts, balance: $total_balance, new balance: $new_total_balance" >&2 | ||
|
||
function make_balance_expr(){ | ||
i=$1 | ||
key=$2 | ||
echo "$key: (((([.[range($i; $num_accounts; $num_keys_and_ghost)].balance | tonumber] | add) + $KEY_BALANCE)/$new_total_balance*10000|round/100 | tostring) + \"%\")" | ||
} | ||
|
||
balance_expr=$({ i=0; while [[ $i -lt $num_keys ]]; do | ||
j=$((i+1)) | ||
make_balance_expr $i "${!j}" | ||
i=$j | ||
done } | tr "\n" "," | head -c -1) | ||
|
||
echo "Balance map:" >&2 | ||
jq <$ledger_file "$pre_filter | {$balance_expr}" 1>&2 | ||
|
||
########################################################## | ||
# Build new ledger | ||
########################################################## | ||
|
||
function make_expr(){ | ||
i=$1 | ||
key=$2 | ||
|
||
# Substitute delegate of some ledger keys with the BP key | ||
echo ".[range($i; $num_accounts; $num_keys_and_ghost)].delegate = \"$key\"" | ||
echo ".[$((i+num_accounts))] = {pk:\"$key\", balance:\"$KEY_BALANCE\"}" | ||
} | ||
|
||
expr=$({ i=0; while [[ $i -lt $num_keys ]]; do | ||
j=$((i+1)) | ||
make_expr $i "${!j}" | ||
i=$j | ||
done } | tr "\n" "|" | head -c -1) | ||
|
||
jq <$ledger_file "$pre_filter | $expr" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,204 @@ | ||
open Core | ||
open Integration_test_lib | ||
|
||
module Make (Inputs : Intf.Test.Inputs_intf) = struct | ||
open Inputs | ||
open Engine | ||
open Dsl | ||
|
||
open Test_common.Make (Inputs) | ||
|
||
(* TODO: find a way to avoid this type alias (first class module signatures restrictions make this tricky) *) | ||
type network = Network.t | ||
|
||
type node = Network.Node.t | ||
|
||
type dsl = Dsl.t | ||
|
||
let num_extra_keys = 100 | ||
|
||
let slot_tx_end = 5 | ||
|
||
let slot_chain_end = 8 | ||
|
||
let sender_account_prefix = "sender-account-" | ||
|
||
let config = | ||
let open Test_config in | ||
{ default with | ||
requires_graphql = true | ||
; genesis_ledger = | ||
[ { Test_Account.account_name = "receiver-key" | ||
; balance = "9999999" | ||
; timing = Untimed | ||
} | ||
; { account_name = "sender-1-key"; balance = "0"; timing = Untimed } | ||
; { account_name = "sender-2-key"; balance = "0"; timing = Untimed } | ||
; { account_name = "sender-3-key"; balance = "0"; timing = Untimed } | ||
; { account_name = "snark-node-key"; balance = "0"; timing = Untimed } | ||
] | ||
@ List.init num_extra_keys ~f:(fun i -> | ||
{ Test_Account.account_name = | ||
sprintf "%s-%d" sender_account_prefix i | ||
; balance = "1000" | ||
; timing = Untimed | ||
} ) | ||
; block_producers = | ||
[ { node_name = "receiver"; account_name = "receiver-key" } | ||
; { node_name = "sender-1"; account_name = "sender-1-key" } | ||
; { node_name = "sender-2"; account_name = "sender-2-key" } | ||
; { node_name = "sender-3"; account_name = "sender-3-key" } | ||
] | ||
; snark_coordinator = | ||
Some | ||
{ node_name = "snark-node" | ||
; account_name = "snark-node-key" | ||
; worker_nodes = 4 | ||
} | ||
; txpool_max_size = 10_000_000 | ||
; snark_worker_fee = "0.0002" | ||
; num_archive_nodes = 0 | ||
; proof_config = | ||
{ proof_config_default with | ||
work_delay = Some 1 | ||
; transaction_capacity = | ||
Some Runtime_config.Proof_keys.Transaction_capacity.small | ||
} | ||
; slot_tx_end = Some slot_tx_end | ||
; slot_chain_end = Some slot_chain_end | ||
} | ||
|
||
let fee = Currency.Fee.of_nanomina_int_exn 10_000_000 | ||
|
||
let amount = Currency.Amount.of_nanomina_int_exn 10_000_000 | ||
|
||
let tx_delay_ms = 5000 | ||
|
||
let run network t = | ||
let open Malleable_error.Let_syntax in | ||
let logger = Logger.create () in | ||
let num_slots = slot_chain_end + 2 in | ||
let receiver = | ||
String.Map.find_exn (Network.block_producers network) "receiver" | ||
in | ||
let%bind receiver_pub_key = pub_key_of_node receiver in | ||
let bp_senders = | ||
String.Map.remove (Network.block_producers network) "receiver" | ||
|> String.Map.data | ||
in | ||
let sender_kps = | ||
String.Map.fold (Network.genesis_keypairs network) ~init:[] | ||
~f:(fun ~key ~data acc -> | ||
if String.is_prefix key ~prefix:sender_account_prefix then data :: acc | ||
else acc ) | ||
in | ||
let sender_priv_keys = | ||
List.map sender_kps ~f:(fun kp -> kp.keypair.private_key) | ||
in | ||
let pk_to_string = Signature_lib.Public_key.Compressed.to_base58_check in | ||
[%log info] "receiver: %s" (pk_to_string receiver_pub_key) ; | ||
let%bind () = | ||
Malleable_error.List.iter sender_kps ~f:(fun s -> | ||
let pk = s.keypair.public_key |> Signature_lib.Public_key.compress in | ||
return ([%log info] "sender: %s" (pk_to_string pk)) ) | ||
in | ||
let window_ms = | ||
(Network.constraint_constants network).block_window_duration_ms | ||
in | ||
let all_nodes = Network.all_mina_nodes network in | ||
let%bind () = | ||
wait_for t | ||
(Wait_condition.nodes_to_initialize (String.Map.data all_nodes)) | ||
in | ||
let genesis_timestamp = | ||
Block_time.to_time_exn | ||
@@ Block_time.of_int64 | ||
(Network.genesis_constants network).protocol.genesis_state_timestamp | ||
in | ||
let end_t = | ||
Time.add genesis_timestamp | ||
(Time.Span.of_ms @@ float_of_int (num_slots * window_ms)) | ||
in | ||
let slot_tx_end = | ||
Mina_numbers.Global_slot_since_hard_fork.of_int slot_tx_end | ||
in | ||
let slot_chain_end = | ||
Mina_numbers.Global_slot_since_hard_fork.of_int slot_chain_end | ||
in | ||
let%bind () = | ||
section_hard "spawn transaction sending" | ||
(let num_payments = num_slots * window_ms / tx_delay_ms in | ||
let repeat_count = Unsigned.UInt32.of_int num_payments in | ||
let repeat_delay_ms = Unsigned.UInt32.of_int tx_delay_ms in | ||
let num_sender_keys = List.length sender_priv_keys in | ||
let n_bp_senders = List.length bp_senders in | ||
let keys_per_sender = num_sender_keys / n_bp_senders in | ||
[%log info] | ||
"will now send %d payments from as many accounts. %d nodes will \ | ||
send %d payments each from distinct keys" | ||
num_payments n_bp_senders keys_per_sender ; | ||
Malleable_error.List.fold ~init:sender_priv_keys bp_senders | ||
~f:(fun keys node -> | ||
let keys0, rest = List.split_n keys keys_per_sender in | ||
Integration_test_lib.Graphql_requests.must_send_test_payments | ||
~repeat_count ~repeat_delay_ms ~logger ~senders:keys0 | ||
~receiver_pub_key ~amount ~fee | ||
(Network.Node.get_ingress_uri node) | ||
>>| const rest ) | ||
>>| const () ) | ||
in | ||
let%bind () = | ||
section | ||
(Printf.sprintf "wait until slot %d" num_slots) | ||
Async.(at end_t >>= const Malleable_error.ok_unit) | ||
in | ||
let ok_if_true s = | ||
Malleable_error.ok_if_true ~error:(Error.of_string s) ~error_type:`Soft | ||
in | ||
let%bind blocks = | ||
Integration_test_lib.Graphql_requests | ||
.must_get_best_chain_for_slot_end_test ~max_length:(2 * num_slots) ~logger | ||
(Network.Node.get_ingress_uri receiver) | ||
in | ||
let%bind () = | ||
section "blocks produced before slot_tx_end" | ||
( ok_if_true "only empty blocks were produced before slot_tx_end" | ||
@@ List.exists blocks ~f:(fun block -> | ||
Mina_numbers.Global_slot_since_hard_fork.( | ||
block.slot < slot_tx_end) | ||
&& ( block.command_transaction_count <> 0 | ||
|| block.snark_work_count <> 0 | ||
|| Currency.Amount.(block.coinbase <> zero) ) ) ) | ||
in | ||
let%bind () = | ||
section "blocks produced after slot_tx_end" | ||
(Malleable_error.List.iter blocks ~f:(fun block -> | ||
let msg = | ||
Printf.sprintf | ||
"non-empty block after slot_tx_end. block slot since genesis: \ | ||
%s, txn count: %d, snark work count: %d, coinbase: %s" | ||
(Mina_numbers.Global_slot_since_hard_fork.to_string block.slot) | ||
block.command_transaction_count block.snark_work_count | ||
(Currency.Amount.to_string block.coinbase) | ||
in | ||
ok_if_true msg | ||
( Mina_numbers.Global_slot_since_hard_fork.( | ||
block.slot < slot_tx_end) | ||
|| block.command_transaction_count = 0 | ||
&& block.snark_work_count = 0 | ||
&& Currency.Amount.(block.coinbase = zero) ) ) ) | ||
in | ||
let%bind () = | ||
section "blocks produced before slot_chain_end" | ||
( ok_if_true "no block produced before slot_chain_end" | ||
@@ List.exists blocks ~f:(fun block -> | ||
Mina_numbers.Global_slot_since_hard_fork.( | ||
block.slot < slot_chain_end) ) ) | ||
in | ||
section "no blocks produced after slot_chain_end" | ||
( ok_if_true "blocks produced after slot_chain_end" | ||
@@ not | ||
@@ List.exists blocks ~f:(fun block -> | ||
Mina_numbers.Global_slot_since_hard_fork.( | ||
block.slot >= slot_chain_end) ) ) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module Make : Integration_test_lib.Intf.Test.Functor_intf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please propagate this constant change to the base
compatble
-based branch