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

Upgrade chain simulator #3358

Merged
merged 13 commits into from Oct 22, 2020
Merged

Upgrade chain simulator #3358

merged 13 commits into from Oct 22, 2020

Conversation

radrow
Copy link
Member

@radrow radrow commented Sep 15, 2020

More features, serious block representation, no event discrimination

@radrow radrow requested a review from uwiger October 20, 2020 09:20
@radrow radrow marked this pull request as ready for review October 20, 2020 10:05
Copy link
Contributor

@gorbak25 gorbak25 left a comment

Choose a reason for hiding this comment

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

Setting the PrevKeyHash is bugged.

ok = push(CreateTx),
SignedTx = create_tx(Config),
TxHash = aetx_sign:hash(SignedTx),
ct:log("TxHash ~p", [TxHash]),
Copy link
Contributor

Choose a reason for hiding this comment

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

This log message wasn't here before.

@@ -674,8 +677,16 @@ init_per_group(GrpName, Config) ->
Config;
_ ->
{ok, ChainP} = start_chain_process(),
{ok, #{pubkey := Initiator, privkey := InitiatorSK}} = aec_chain_sim:new_account(1000000000000000000000000000000000000000000000000000000000000000),
Copy link
Contributor

Choose a reason for hiding this comment

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

please define multipliers:

100000000000000000000000000000000000000000000000 -> ... * ?AE_MULT

@@ -674,8 +677,16 @@ init_per_group(GrpName, Config) ->
Config;
_ ->
{ok, ChainP} = start_chain_process(),
{ok, #{pubkey := Initiator, privkey := InitiatorSK}} = aec_chain_sim:new_account(1000000000000000000000000000000000000000000000000000000000000000),
{ok, #{pubkey := Responder, privkey := ResponderSK}} = aec_chain_sim:new_account(1000000000000000000000000000000000000000000000000000000000000000),
Copy link
Contributor

Choose a reason for hiding this comment

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

How many AE is that?

Copy link
Member Author

Choose a reason for hiding this comment

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

"enough"

%%
%% Equivalent to add_keyblock(main)
%%
add_keyblock() ->
add_keyblock(main).

-spec block_by_hash(block_hash()) -> {ok, sim_keyblock() |sim_microblock()}.
-spec block_by_hash(block_hash()) -> {ok, aec_blocks:key_block() |aec_blocks:micro_block()}.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
-spec block_by_hash(block_hash()) -> {ok, aec_blocks:key_block() |aec_blocks:micro_block()}.
-spec block_by_hash(block_hash()) -> {ok, aec_blocks:block()}.

#{hash := PrevHash, header := TopHdr} = hd(Blocks),
#{block := B} = hd(Blocks),
TopHdr = aec_blocks:to_header(B),
{ok, PrevHash} = aec_headers:hash_header(TopHdr),
?LOG("PrevHash = ~p", [PrevHash]),
PrevKeyHash = aec_headers:prev_key_hash(TopHdr),
Copy link
Contributor

Choose a reason for hiding this comment

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

@uwiger @radrow It seems that the original chain simulator also sets the PrevKeyHash improperly.
This will always point to the genesis hash.
Let me demonstrate:

1. Genesis
2. Genesis <- Gen1Micro1(Prev: Genesis, PrevKey: Genesis) <- ...
3. Genesis <- ... <- Key1(Prev: Gen1MicroN, PrevKey: Genesis)
4. Genesis <- ... <- Key1(Prev: Gen1MicroN, PrevKey: Genesis) <- Gen2Micro1(Prev: Key1, PrevKey: **Genesis**

The correct code:

PrevKeyHash = case aec_headers:is_key(TopHdr) of true -> TopHdrHash; false -> aec_headers:prev_key_hash(TopHdr) end,

Copy link
Member

@uwiger uwiger left a comment

Choose a reason for hiding this comment

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

LGTM

@erlmachinedev
Copy link
Contributor

The simulator is getting mature and becomes an efficient tool and from my perspective, that deserves for some kind of refactoring later (@gorbak25, @radrow, @uwiger your thoughts about?). Also glad to see aec_trees, aec_headers for now it's more real).

In the future, it could be nice to see some refactoring here like:

  1. To arrange simulator into the separated dir and to decouple into 3 parts: simulator process module, parameterizing API module, internal implementation module;
  2. To provide instantiation facilities. We have to provide modelling for different scenarios, especially for the HC parent chains modelling facility;
  3. To provide parameterizing API (at least to able to set up some stuff like BIG_AMOUNT :) before the run)

P.S. We just got a small merge conflict here, after you merge I am going to fix my part too. (We have to pass predefined chain state here (I do in the parent manager, as we have configurated genesis pointer before sim is run)

@radrow radrow merged commit dc68bdd into hyperchains-master Oct 22, 2020
gorbak25 added a commit that referenced this pull request Nov 5, 2020
* First edits to the chain sim. Added staking contract.

* Txs are passing

* Fixed some SC tests, HTTP is failing

* checkpoint

* typo

* Fix event type

* Fix events

* Fix the upgrade

* Chain sim is finally fully operational

* Fix some mismatches

* Cleanup

* Fix header hash, push aesophia, minor sanity

* Minor fix

Co-authored-by: Grzegorz Uriasz <gorbak25@gmail.com>
gorbak25 added a commit that referenced this pull request Nov 6, 2020
* First edits to the chain sim. Added staking contract.

* Txs are passing

* Fixed some SC tests, HTTP is failing

* checkpoint

* typo

* Fix event type

* Fix events

* Fix the upgrade

* Chain sim is finally fully operational

* Fix some mismatches

* Cleanup

* Fix header hash, push aesophia, minor sanity

* Minor fix

Co-authored-by: Grzegorz Uriasz <gorbak25@gmail.com>
gorbak25 added a commit that referenced this pull request Jan 26, 2021
* First edits to the chain sim. Added staking contract.

* Txs are passing

* Fixed some SC tests, HTTP is failing

* checkpoint

* typo

* Fix event type

* Fix events

* Fix the upgrade

* Chain sim is finally fully operational

* Fix some mismatches

* Cleanup

* Fix header hash, push aesophia, minor sanity

* Minor fix

Co-authored-by: Grzegorz Uriasz <gorbak25@gmail.com>
gorbak25 added a commit that referenced this pull request Feb 9, 2021
* First edits to the chain sim. Added staking contract.

* Txs are passing

* Fixed some SC tests, HTTP is failing

* checkpoint

* typo

* Fix event type

* Fix events

* Fix the upgrade

* Chain sim is finally fully operational

* Fix some mismatches

* Cleanup

* Fix header hash, push aesophia, minor sanity

* Minor fix

Co-authored-by: Grzegorz Uriasz <gorbak25@gmail.com>
gorbak25 added a commit that referenced this pull request Mar 8, 2021
* First edits to the chain sim. Added staking contract.

* Txs are passing

* Fixed some SC tests, HTTP is failing

* checkpoint

* typo

* Fix event type

* Fix events

* Fix the upgrade

* Chain sim is finally fully operational

* Fix some mismatches

* Cleanup

* Fix header hash, push aesophia, minor sanity

* Minor fix

Co-authored-by: Grzegorz Uriasz <gorbak25@gmail.com>
@cytadela8 cytadela8 deleted the hyperchains-chain-sim branch March 23, 2021 09:03
myotp added a commit that referenced this pull request Apr 28, 2021
…n branch (#2938)

Upgrade chain simulator (#3358)

* First edits to the chain sim. Added staking contract.

* Txs are passing

* Fixed some SC tests, HTTP is failing

* checkpoint

* typo

* Fix event type

* Fix events

* Fix the upgrade

* Chain sim is finally fully operational

* Fix some mismatches

* Cleanup

* Fix header hash, push aesophia, minor sanity

* Minor fix

Co-authored-by: Grzegorz Uriasz <gorbak25@gmail.com>
myotp added a commit that referenced this pull request Apr 30, 2021
Upgrade chain simulator (#3358)

* First edits to the chain sim. Added staking contract.

* Txs are passing

* Fixed some SC tests, HTTP is failing

* checkpoint

* typo

* Fix event type

* Fix events

* Fix the upgrade

* Chain sim is finally fully operational

* Fix some mismatches

* Cleanup

* Fix header hash, push aesophia, minor sanity

* Minor fix

Co-authored-by: Grzegorz Uriasz <gorbak25@gmail.com>
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

4 participants