Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions foundry/auto_self_nominate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<AccountProvider>,
Expand Down Expand Up @@ -134,8 +134,13 @@ 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 {
cdebug!(ENGINE, "No need self nominate");
if candidate_need_nomination.nomination_ends_at + NEED_NOMINATION_UNDER_TERM_LEFT <= current_term {
Copy link
Author

Choose a reason for hiding this comment

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

We missed this condition.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I think it should be reversed.

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) {
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion test/src/e2e.dynval/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ async function createNodes<T>(options: {
"--self-nomination-target-deposit",
"10",
"--self-nomination-interval",
"10"
"1000"
);
}
const modifier = modify(validator, i);
Expand Down