From 8ae83d72cdbeb3beed9bb701630b0edb54bd1992 Mon Sep 17 00:00:00 2001 From: Park Juhyung Date: Wed, 29 Jan 2020 10:50:18 +0900 Subject: [PATCH 1/6] Use proper NEED_NOMINATION_UNDER_TERM_LEFT value Foundry should send a self-nomination transaction before too late --- foundry/auto_self_nominate.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/foundry/auto_self_nominate.rs b/foundry/auto_self_nominate.rs index 43b74f8b34..0c86c655e6 100644 --- a/foundry/auto_self_nominate.rs +++ b/foundry/auto_self_nominate.rs @@ -31,7 +31,7 @@ use std::sync::Arc; use std::thread; use std::time::Duration; -const NEED_NOMINATION_UNDER_TERM_LEFT: u64 = 1; +const NEED_NOMINATION_UNDER_TERM_LEFT: u64 = 3; #[derive(Clone)] struct SelfSigner { account_provider: Arc, From 438880a8b6efbacc265bcb4ce121df76179f1a49 Mon Sep 17 00:00:00 2001 From: Park Juhyung Date: Wed, 29 Jan 2020 11:15:35 +0900 Subject: [PATCH 2/6] Fix the wrong condition in the auto_self_nominate.rs file Foundry should send a self-nomination transaction before the nomination ends. --- foundry/auto_self_nominate.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/foundry/auto_self_nominate.rs b/foundry/auto_self_nominate.rs index 0c86c655e6..e6ba420546 100644 --- a/foundry/auto_self_nominate.rs +++ b/foundry/auto_self_nominate.rs @@ -134,7 +134,7 @@ impl AutoSelfNomination { let candidate = Candidates::load_from_state(&state).unwrap(); if candidate.get_candidate(&address).is_some() { let candidate_need_nomination = candidate.get_candidate(&address).unwrap(); - if candidate_need_nomination.nomination_ends_at <= current_term + NEED_NOMINATION_UNDER_TERM_LEFT { + if candidate_need_nomination.nomination_ends_at + NEED_NOMINATION_UNDER_TERM_LEFT <= current_term { cdebug!(ENGINE, "No need self nominate"); return } From f97654a93c30550eecceb270b32a5210c2ba0c30 Mon Sep 17 00:00:00 2001 From: Park Juhyung Date: Wed, 29 Jan 2020 11:17:38 +0900 Subject: [PATCH 3/6] Add more log in the auto_self_nominate file --- foundry/auto_self_nominate.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/foundry/auto_self_nominate.rs b/foundry/auto_self_nominate.rs index e6ba420546..e4776d6c3e 100644 --- a/foundry/auto_self_nominate.rs +++ b/foundry/auto_self_nominate.rs @@ -135,7 +135,12 @@ impl AutoSelfNomination { if candidate.get_candidate(&address).is_some() { let candidate_need_nomination = candidate.get_candidate(&address).unwrap(); if candidate_need_nomination.nomination_ends_at + NEED_NOMINATION_UNDER_TERM_LEFT <= current_term { - cdebug!(ENGINE, "No need self nominate"); + cdebug!( + ENGINE, + "No need self nominate. nomination_ends_at: {}, current_term: {}", + candidate_need_nomination.nomination_ends_at, + current_term + ); return } if candidate_need_nomination.deposit.lt(&targetdep) { @@ -187,7 +192,9 @@ impl AutoSelfNomination { let signed = SignedTransaction::try_new(unverified).expect("secret is valid so it's recoverable"); match client.queue_own_transaction(signed) { - Ok(_) => {} + Ok(_) => { + cinfo!(ENGINE, "Send self nominate transaction"); + } Err(e) => { cerror!(ENGINE, "Failed to queue self nominate transaction: {}", e); } From 625bbca1021e8155af628bf93548e7a456463545 Mon Sep 17 00:00:00 2001 From: Park Juhyung Date: Wed, 29 Jan 2020 11:09:00 +0900 Subject: [PATCH 4/6] Fix the selfnomination.test.ts Since the bob is using the auto-self-nomination, we don't need to send the self-nomination transaction manually in the test. Occasionally, the test failed because of the seq conflict with auto-selfnomination and the manual transaction. --- test/src/e2e.dynval/2/selfnomination.test.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/test/src/e2e.dynval/2/selfnomination.test.ts b/test/src/e2e.dynval/2/selfnomination.test.ts index a74b623b52..5680bf08d8 100644 --- a/test/src/e2e.dynval/2/selfnomination.test.ts +++ b/test/src/e2e.dynval/2/selfnomination.test.ts @@ -62,16 +62,13 @@ describe("Auto Self Nomination", function() { }); const aliceNode = findNode(nodes, alice); - const bobNode = findNode(nodes, bob); const selfNominationHash = await selfNominate( aliceNode.sdk, alice, 10 ); - const bobselfNomination = await selfNominate(bobNode.sdk, bob, 10); await aliceNode.waitForTx(selfNominationHash); - await bobNode.waitForTx(bobselfNomination); - + // bob will send self-nomination transaction automatically. const beforeCandidates = await stake.getCandidates(nodes[0].sdk); expect( From d881847feac23afb0e6eafc4aa3833775183dde0 Mon Sep 17 00:00:00 2001 From: Park Juhyung Date: Wed, 29 Jan 2020 11:10:16 +0900 Subject: [PATCH 5/6] Use auto-self-nomination-interval as 1 second 10ms was too short. --- test/src/e2e.dynval/setup.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/src/e2e.dynval/setup.ts b/test/src/e2e.dynval/setup.ts index 4528f76d69..5f3a54e50c 100644 --- a/test/src/e2e.dynval/setup.ts +++ b/test/src/e2e.dynval/setup.ts @@ -157,7 +157,7 @@ async function createNodes(options: { "--self-nomination-target-deposit", "10", "--self-nomination-interval", - "10" + "1000" ); } const modifier = modify(validator, i); From 0a39a3ef396e74f5eb2ad50700b5eff25cf8542f Mon Sep 17 00:00:00 2001 From: Park Juhyung Date: Wed, 29 Jan 2020 11:23:05 +0900 Subject: [PATCH 6/6] Rename selfnomination.test.ts to autoselfnomination.test.ts The purpose of the test is testing auto-self-nomination. --- .../2/{selfnomination.test.ts => autoselfnomination.test.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test/src/e2e.dynval/2/{selfnomination.test.ts => autoselfnomination.test.ts} (100%) diff --git a/test/src/e2e.dynval/2/selfnomination.test.ts b/test/src/e2e.dynval/2/autoselfnomination.test.ts similarity index 100% rename from test/src/e2e.dynval/2/selfnomination.test.ts rename to test/src/e2e.dynval/2/autoselfnomination.test.ts