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

Dag sync test case use 0 as fork number #4130

Merged

Conversation

jackzhhuang
Copy link
Collaborator

Pull request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Other information

@@ -832,7 +873,9 @@ impl BlockChain {
&tips_hash, blues
);
let mut blue_blocks = vec![];
let _selected_parent = blues.remove(0);
let selected_parent = blues.remove(0);
Copy link
Collaborator

@nkysg nkysg Jun 5, 2024

Choose a reason for hiding this comment

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

https://doc.rust-lang.org/std/vec/struct.Vec.html#method.remove

Removes and returns the element at position index within the vector, shifting all elements after it to the left.


Note: Because this shifts over the remaining elements, it has a worst-case performance of O(n). If you don’t need the order of elements to be preserved, use [swap_remove](https://doc.rust-lang.org/std/vec/struct.Vec.html#method.swap_remove) instead. If you’d like to remove elements from the beginning of the Vec, consider using [VecDeque::pop_front](https://doc.rust-lang.org/std/collections/struct.VecDeque.html#method.pop_front) instead.

Is this place we need check blue_blocks length greater than 1. I noticed there is another place have the same code.

let __selected_parent = blues.remove(0);

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Let me think about it. Maybe it's better to do it.
.

@@ -362,7 +387,9 @@ where
);
let mut blue_blocks = vec![];

let __selected_parent = blues.remove(0);
let selected_parent = blues.remove(0);
Copy link
Collaborator

Choose a reason for hiding this comment

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

the same issue

@nkysg nkysg self-requested a review June 5, 2024 12:15
let __selected_parent = blues.remove(0);
let selected_parent = blues.remove(0);
previous_header =
self.get_dag_previous_header(previous_header, selected_parent)?;
Copy link
Collaborator

@simonjiao simonjiao Jun 5, 2024

Choose a reason for hiding this comment

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

What's the purpose of updating previous_header here? Do we need to update the miner's block forging process?

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 maybe he wants to solve header not update but blockdag tips update. @jackzhhuang

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes

Copy link
Collaborator

Choose a reason for hiding this comment

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

I have two questions, the second one? Is there a issue tracking on it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is necessary to update the chain object in miner service.
This is the case caused by the 0 dag fork height, see test_block_chain_reset.

@@ -718,7 +718,7 @@ static G_EMPTY_BOOT_NODES: Lazy<Vec<MultiaddrWithPeerId>> = Lazy::new(Vec::new);
const ONE_DAY: u64 = 86400;

// for test
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please remove this constant and use genesis config to set dag height. See G_DEV_CONFIG.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

OK

Copy link
Collaborator Author

@jackzhhuang jackzhhuang Jun 6, 2024

Choose a reason for hiding this comment

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

Historically, this constant is used for transaction timeout and if you make sure that it is should be removed, you remove in your branch.
There are two logic in test case: one for the single chain and other for the dag chain. Both need running in the test net and 0 as fork number. But I saw the fork height in Genesis Config is u64::MAX which is not suitable for those two cases.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

And some test case, such as test_multiple_node_sync, the miner service is a must to mint blocks automatically. But in dev net, because the config set, the block will not be minted leading to failure or timeout.

Copy link
Collaborator

@simonjiao simonjiao Jun 6, 2024

Choose a reason for hiding this comment

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

As you said, there's still lots of failed cases which need to a fix if we set dag-fork-height as ZERO in genesis config, right? I don't think this PR has done the work as it's title says, right? Please do the job like what you said.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

And some test case, such as test_multiple_node_sync, the miner service is a must to mint blocks automatically. But in dev net, because the config set, the block will not be minted leading to failure or timeout.

So change it to right value, run the tests and fix it. THX.

I really did not understand what you want. But this time, you mean I have to do the job that let the starcoin run in fork height 0 by using the config you defined? If it is, that is fine I am happy to do that. But you can say your requirement directly next time.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Why no checking the dag or not ? This is the branch sync test cases using dag fork height 0 run successfully. Any other big feature or improvement should be in other branches.

Yes. No need to check it, The genesis configuration make sure it always be a DAG, every blocks, headers are constructed for DAG.

Copy link
Collaborator

@simonjiao simonjiao Jun 6, 2024

Choose a reason for hiding this comment

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

And some test case, such as test_multiple_node_sync, the miner service is a must to mint blocks automatically. But in dev net, because the config set, the block will not be minted leading to failure or timeout.

So change it to right value, run the tests and fix it. THX.

I really did not understand what you want. But this time, you mean I have to do the job that let the starcoin run in fork height 0 by using the config you defined? If it is, that is fine I am happy to do that. But you can say your requirement directly next time.

If you donot want it, don't do it. This is a small team, everyone should do his best.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As the pr title shows and at the meeting I was assigned to let the test cases ci run successfullly at fork height 0 and the rest will be done in your branch, now you ask me to do the rest? Ensure this or I am afraid of the code conflict.

Copy link
Collaborator

Choose a reason for hiding this comment

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

As the pr title shows and at the meeting I was assigned to let the test cases ci run successfullly at fork height 0 and the rest will be done in your branch, now you ask me to do the rest? Ensure this or I am afraid of the code conflict.

Suit yourself.

@@ -233,7 +233,7 @@ impl SyncService {
storage.get_block_info(current_block_id)?.ok_or_else(|| {
format_err!("Can not find block info by id: {}", current_block_id)
})?;
let dag_fork_height = chain_service.dag_fork_height().await?;
let dag_fork_height = Some(config.net().genesis_config().dag_effective_height);
Copy link
Collaborator

@simonjiao simonjiao Jun 7, 2024

Choose a reason for hiding this comment

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

For safety, we need get to it from statedb, technically, the pre-set value is only used when executing genesis block.

Copy link
Member

Choose a reason for hiding this comment

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

it means this value can be changed through somewhere, such as framework?

Copy link
Collaborator

Choose a reason for hiding this comment

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

it means this value can be changed through somewhere, such as framework?

Yes. DAO is one way to reset it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we still need dag_fork_height ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Because the code maintains synchronization logic of the sing chain and dag and it is flexible.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I remember that sanlee42 suggests that we use some cfg macros @sanlee42 .

@@ -48,18 +48,15 @@ fn test_transaction_info_and_proof_1() -> Result<()> {
let config = Arc::new(NodeConfig::random_for_test());
let mut block_chain = test_helper::gen_blockchain_for_test(config.net())?;

// set the flexidag fork height to G_TEST_DAG_FORK_HEIGHT
block_chain
.dag()
.save_dag_state(*G_TEST_DAG_FORK_STATE_KEY, DagState { tips: vec![] })?;
Copy link
Member

Choose a reason for hiding this comment

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

why we still need G_TEST_DAG_FORK_STATE_KEY?

use starcoin_config::genesis_config::G_TEST_DAG_FORK_STATE_KEY;
use starcoin_dag::consensusdb::consenses_state::DagState;

dag.save_dag_state(*G_TEST_DAG_FORK_STATE_KEY, DagState { tips: vec![] })?;
Copy link
Member

Choose a reason for hiding this comment

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

consider remove it?

@@ -233,7 +233,7 @@ impl SyncService {
storage.get_block_info(current_block_id)?.ok_or_else(|| {
format_err!("Can not find block info by id: {}", current_block_id)
})?;
let dag_fork_height = chain_service.dag_fork_height().await?;
let dag_fork_height = Some(config.net().genesis_config().dag_effective_height);
Copy link
Member

Choose a reason for hiding this comment

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

it means this value can be changed through somewhere, such as framework?

@sanlee42 sanlee42 removed the request for review from jolestar June 7, 2024 03:05
@jackzhhuang
Copy link
Collaborator Author

I am still working on the code. I will periodically save and stage the changes.

@sanlee42
Copy link
Member

sanlee42 commented Jun 7, 2024

I am still working on the code. I will periodically save and stage the changes.

You can draft it until it finish.

@jackzhhuang jackzhhuang marked this pull request as draft June 7, 2024 07:29
@jackzhhuang jackzhhuang marked this pull request as ready for review June 7, 2024 10:49
sync/src/tasks/tests_dag.rs Outdated Show resolved Hide resolved
@@ -105,6 +105,9 @@ pub async fn test_sync_invalid_target() -> Result<()> {
Ok(())
}

#[ignore = "This test is for the scenario that a block failed to connect to the main will be stored in the \
failure storage and the sync will return failure instantly the next time the block shows up again, \
which is no longer suitable for the dag"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Change the networkid to network with u64::max dag fork height, such as Test. This test can be fixed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It cannot be fixed as you said. You try and will know.

Copy link
Collaborator

@simonjiao simonjiao Jun 11, 2024

Choose a reason for hiding this comment

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

emm... It did fail. This is a case for the single chain, and should be fixed by this walkaround solution. Could some updates break the procedures? But anyway, it's your call.

sync/src/tasks/mock.rs Show resolved Hide resolved
sync/src/tasks/tests_dag.rs Show resolved Hide resolved
sync/src/tasks/tests_dag.rs Outdated Show resolved Hide resolved
@jackzhhuang jackzhhuang enabled auto-merge (squash) June 18, 2024 17:26
@jackzhhuang jackzhhuang merged commit 6069524 into starcoinorg:dag-master Jun 19, 2024
2 of 4 checks passed
jackzhhuang added a commit to jackzhhuang/starcoin that referenced this pull request Jun 19, 2024
* use 0 as fork number

* fix some test case that uses 0 as fork number

* check the blues returned by the ghostdata whether it is empty

* use genesis config to get the dag fork number

* fix clippy

* basic sync dag test case pass

* fix all sync test case running in the dag using the genesis config

* 1, use match to determine the way of the execution and verification
2, return test message in apply failed function

* fix test_flexidag_config_get_for_halley

* add dag test genesis

* add is dag test in test_example_config_compact

* remove the used files and codes

* fix test_custom_genesis

* add is dag test beside the is test

* fix test_generated_schema_are_up_to_date_in_git

* fix fmt

* add dag test in node.json

* add check genesis identical between two nodes in test_sync_dag_blocks

* return error if no blue uncle found, no expect no panic

* add test case test_dag_uncles

* fix genesis generating problem

* renew halley genesis

* renew halley genesis

* renew halley genesis

* remove the dag init in dag block execution process

* 1, change dag type to chain type
2, remove dag genesisi enum in chain type

* use 0 as fork number

* fix some test case that uses 0 as fork number

* check the blues returned by the ghostdata whether it is empty

* use genesis config to get the dag fork number

* fix clippy

* basic sync dag test case pass

* fix all sync test case running in the dag using the genesis config

* 1, use match to determine the way of the execution and verification
2, return test message in apply failed function

* fix test_flexidag_config_get_for_halley

* add dag test genesis

* add is dag test in test_example_config_compact

* remove the used files and codes

* fix test_custom_genesis

* add is dag test beside the is test

* fix test_generated_schema_are_up_to_date_in_git

* fix fmt

* add dag test in node.json

* add check genesis identical between two nodes in test_sync_dag_blocks

* return error if no blue uncle found, no expect no panic

* add test case test_dag_uncles

* fix genesis generating problem

* renew halley genesis

* renew halley genesis

* renew halley genesis

* remove the dag init in dag block execution process

* 1, change dag type to chain type
2, remove dag genesisi enum in chain type

* Fix clippy

* rebase dag master

* add new dag block subscribe

---------

Co-authored-by: 0xa <hit.cs.lijun@gmail.com>
jackzhhuang added a commit to jackzhhuang/starcoin that referenced this pull request Jun 21, 2024
* use 0 as fork number

* fix some test case that uses 0 as fork number

* check the blues returned by the ghostdata whether it is empty

* use genesis config to get the dag fork number

* fix clippy

* basic sync dag test case pass

* fix all sync test case running in the dag using the genesis config

* 1, use match to determine the way of the execution and verification
2, return test message in apply failed function

* fix test_flexidag_config_get_for_halley

* add dag test genesis

* add is dag test in test_example_config_compact

* remove the used files and codes

* fix test_custom_genesis

* add is dag test beside the is test

* fix test_generated_schema_are_up_to_date_in_git

* fix fmt

* add dag test in node.json

* add check genesis identical between two nodes in test_sync_dag_blocks

* return error if no blue uncle found, no expect no panic

* add test case test_dag_uncles

* fix genesis generating problem

* renew halley genesis

* renew halley genesis

* renew halley genesis

* remove the dag init in dag block execution process

* 1, change dag type to chain type
2, remove dag genesisi enum in chain type

* use 0 as fork number

* fix some test case that uses 0 as fork number

* check the blues returned by the ghostdata whether it is empty

* use genesis config to get the dag fork number

* fix clippy

* basic sync dag test case pass

* fix all sync test case running in the dag using the genesis config

* 1, use match to determine the way of the execution and verification
2, return test message in apply failed function

* fix test_flexidag_config_get_for_halley

* add dag test genesis

* add is dag test in test_example_config_compact

* remove the used files and codes

* fix test_custom_genesis

* add is dag test beside the is test

* fix test_generated_schema_are_up_to_date_in_git

* fix fmt

* add dag test in node.json

* add check genesis identical between two nodes in test_sync_dag_blocks

* return error if no blue uncle found, no expect no panic

* add test case test_dag_uncles

* fix genesis generating problem

* renew halley genesis

* renew halley genesis

* renew halley genesis

* remove the dag init in dag block execution process

* 1, change dag type to chain type
2, remove dag genesisi enum in chain type

* Fix clippy

* rebase dag master

* add new dag block subscribe

---------

Co-authored-by: 0xa <hit.cs.lijun@gmail.com>
jackzhhuang added a commit that referenced this pull request Jun 25, 2024
* use 0 as fork number

* fix some test case that uses 0 as fork number

* check the blues returned by the ghostdata whether it is empty

* use genesis config to get the dag fork number

* fix clippy

* basic sync dag test case pass

* fix all sync test case running in the dag using the genesis config

* 1, use match to determine the way of the execution and verification
2, return test message in apply failed function

* fix test_flexidag_config_get_for_halley

* add dag test genesis

* add is dag test in test_example_config_compact

* remove the used files and codes

* fix test_custom_genesis

* add is dag test beside the is test

* fix test_generated_schema_are_up_to_date_in_git

* fix fmt

* add dag test in node.json

* add check genesis identical between two nodes in test_sync_dag_blocks

* return error if no blue uncle found, no expect no panic

* add test case test_dag_uncles

* fix genesis generating problem

* renew halley genesis

* renew halley genesis

* renew halley genesis

* remove the dag init in dag block execution process

* 1, change dag type to chain type
2, remove dag genesisi enum in chain type

* use 0 as fork number

* fix some test case that uses 0 as fork number

* check the blues returned by the ghostdata whether it is empty

* use genesis config to get the dag fork number

* fix clippy

* basic sync dag test case pass

* fix all sync test case running in the dag using the genesis config

* 1, use match to determine the way of the execution and verification
2, return test message in apply failed function

* fix test_flexidag_config_get_for_halley

* add dag test genesis

* add is dag test in test_example_config_compact

* remove the used files and codes

* fix test_custom_genesis

* add is dag test beside the is test

* fix test_generated_schema_are_up_to_date_in_git

* fix fmt

* add dag test in node.json

* add check genesis identical between two nodes in test_sync_dag_blocks

* return error if no blue uncle found, no expect no panic

* add test case test_dag_uncles

* fix genesis generating problem

* renew halley genesis

* renew halley genesis

* renew halley genesis

* remove the dag init in dag block execution process

* 1, change dag type to chain type
2, remove dag genesisi enum in chain type

* Fix clippy

* rebase dag master

* add new dag block subscribe

---------

Co-authored-by: 0xa <hit.cs.lijun@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.

4 participants