Skip to content

Commit

Permalink
Fork choice and full sync
Browse files Browse the repository at this point in the history
Signed-off-by: Stanislav Frolov <[email protected]>

Resume snapshot download after commits are synced

Signed-off-by: Kostiantyn Stepaniuk <[email protected]>

commits love snapshot

Signed-off-by: Stanislav Frolov <[email protected]>

Fix error, extend test

Signed-off-by: Stanislav Frolov <[email protected]>

move vote recorder; record vote when receive from commits

Signed-off-by: Stanislav Frolov <[email protected]>

Fix p2p_snapshot.py

Signed-off-by: Kostiantyn Stepaniuk <[email protected]>

Improve HeaderAndCommits interface

Signed-off-by: Kostiantyn Stepaniuk <[email protected]>

Remove redundant snapshot::HeadersDownloaded() call

Signed-off-by: Kostiantyn Stepaniuk <[email protected]>

Update forkchoice test

Signed-off-by: Stanislav Frolov <[email protected]>

Move cache from finalizationstate

Signed-off-by: Stanislav Frolov <[email protected]>

cr followup

Signed-off-by: Stanislav Frolov <[email protected]>
  • Loading branch information
frolosofsky committed Feb 5, 2019
1 parent daa60c8 commit 920d70c
Show file tree
Hide file tree
Showing 32 changed files with 1,394 additions and 319 deletions.
2 changes: 2 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ UNITE_CORE_H = \
esperanza/walletextension_deps.h \
esperanza/walletstate.h \
extkey.h \
finalization/cache.h \
finalization/p2p.h \
finalization/vote_recorder.h \
fixed_vector.h \
Expand Down Expand Up @@ -286,6 +287,7 @@ libunite_server_a_SOURCES = \
esperanza/checks.cpp \
esperanza/finalizationstate.cpp \
esperanza/validator.cpp \
finalization/cache.cpp \
finalization/p2p.cpp \
finalization/vote_recorder.cpp \
httprpc.cpp \
Expand Down
1 change: 1 addition & 0 deletions src/Makefile.test.include
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ UNITE_TESTS = \
test/esperanza/finalizationstate_slash_tests.cpp \
test/esperanza/finalizationstate_utils.h \
test/esperanza/finalizationstate_utils.cpp \
test/finalization/commits_tests.cpp \
test/finalization/vote_recorder_tests.cpp \
test/fixed_vector_tests.cpp \
test/getarg_tests.cpp \
Expand Down
14 changes: 14 additions & 0 deletions src/chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,15 @@ class CBlockIndex
void ResetCommits(const std::vector<CTransactionRef> &_commits) {
commits = _commits;
}

bool HasCommits() const {
return static_cast<bool>(commits);
}

const std::vector<CTransactionRef> &GetCommits() const {
assert(HasCommits());
return *commits;
}
};

arith_uint256 GetBlockProof(const CBlockIndex& block);
Expand Down Expand Up @@ -485,6 +494,11 @@ class CChain {
return nullptr;
return vChain[nHeight];
}
// UNIT-E: blockchain::Height compatible operator[].
// In a bright future we will get rid of operator[](int).
CBlockIndex *operator[](blockchain::Height h) const {
return (*this)[static_cast<int>(h)];
}

/** Compare two chains efficiently. */
friend bool operator==(const CChain &a, const CChain &b) {
Expand Down
21 changes: 2 additions & 19 deletions src/consensus/tx_verify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,25 +205,8 @@ bool CheckTransaction(const CTransaction &tx, CValidationState &errState, bool f
return errState.DoS(10, false, REJECT_INVALID, "bad-txns-prevout-null");
}

if (tx.IsVote()) {
const esperanza::FinalizationState *state = esperanza::FinalizationState::GetState();

esperanza::Vote vote;
std::vector<unsigned char> voteSig;

if (!CScript::ExtractVoteFromVoteSignature(tx.vin[0].scriptSig, vote, voteSig)) {
return errState.DoS(10, false, REJECT_INVALID, "bad-vote-data-format");
}
const esperanza::Result res = state->ValidateVote(vote);

if (res != +esperanza::Result::ADMIN_BLACKLISTED &&
res != +esperanza::Result::VOTE_NOT_BY_VALIDATOR) {
finalization::VoteRecorder::GetVoteRecorder()->RecordVote(vote, voteSig);
}

if (res != +esperanza::Result::SUCCESS) {
return errState.DoS(10, false, REJECT_INVALID, "bad-vote-invalid-state");
}
if (tx.IsVote() && !finalization::RecordVote(tx, errState)) {
return false;
}

return true;
Expand Down
6 changes: 6 additions & 0 deletions src/esperanza/adminstate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,10 @@ const AdminParams &AdminState::GetParams() const {
return m_adminParams;
}

bool AdminState::operator==(const AdminState &other) const {
return m_adminPubKeys == other.m_adminPubKeys &&
m_whiteList == other.m_whiteList &&
m_permissioningIsActive == other.m_permissioningIsActive;
}

} // namespace esperanza
1 change: 1 addition & 0 deletions src/esperanza/adminstate.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class AdminState {
void EndPermissioning();
bool IsPermissioningActive() const;
const AdminParams &GetParams() const;
bool operator==(const AdminState &other) const;
};

} // namespace esperanza
Expand Down
10 changes: 10 additions & 0 deletions src/esperanza/checkpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,14 @@ uint64_t Checkpoint::GetPrevDynastyVotes(uint32_t epoch) {
return pair.first->second;
}

bool Checkpoint::operator==(const Checkpoint &other) const {
return m_isJustified == other.m_isJustified &&
m_isFinalized == other.m_isFinalized &&
m_curDynastyDeposits == other.m_curDynastyDeposits &&
m_prevDynastyDeposits == other.m_prevDynastyDeposits &&
m_curDynastyVotes == other.m_curDynastyVotes &&
m_prevDynastyVotes == other.m_prevDynastyVotes &&
m_voteSet == other.m_voteSet;
}

} // namespace esperanza
2 changes: 2 additions & 0 deletions src/esperanza/checkpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class Checkpoint {

uint64_t GetCurDynastyVotes(uint32_t epoch);
uint64_t GetPrevDynastyVotes(uint32_t epoch);

bool operator==(const Checkpoint &other) const;
};

} // namespace esperanza
Expand Down
Loading

0 comments on commit 920d70c

Please sign in to comment.