Skip to content

Commit

Permalink
V1.8.0 (#530)
Browse files Browse the repository at this point in the history
* v1.8.0

* Remove FortCanning from Eunos regtest setting

* Take anchor block deeper to avoid "Anchor too new" error (#531)

* Add tests for epic/*

* Switch fork to EunosPaya (#584)

* Switch canning to paya 2 (#585)

* Switch fork to EunosPaya

* Remove left over canning changes

* Onchain timelock (#562)

* Prevent resign during PRE_ENABLED state (#518)

* Prevent resign during PRE_ENABLED and staking during PRE_RESIGNED.

* Change FortCanning to EunosPaya

* Reduce future block time to 30 seconds (#586)

* Reduce future time to 30 seconds

* Ignore 30s time rule on regtest

* Check for and reject entries with duplicates (#592)

* Check for and reject duplicates

* Allow duplicates as long as overall sigs meet quorum

* Add tests. Update confirms to store unique on signer ID.

* Restore previous behaviour as collection ignores duplicate CKeyIDs

* Hold confirms on BTC TX height, hash and signed CKeyID (#598)

* Add hard coded seed for devnet (#601)
  • Loading branch information
Bushstar authored Jul 15, 2021
1 parent 50f60d4 commit 4d93189
Show file tree
Hide file tree
Showing 33 changed files with 875 additions and 203 deletions.
4 changes: 2 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
dnl require autoconf 2.60 (AS_ECHO/AS_ECHO_N)
AC_PREREQ([2.60])
define(_CLIENT_VERSION_MAJOR, 1)
define(_CLIENT_VERSION_MINOR, 7)
define(_CLIENT_VERSION_REVISION, 11)
define(_CLIENT_VERSION_MINOR, 8)
define(_CLIENT_VERSION_REVISION, 0)
define(_CLIENT_VERSION_BUILD, 0)
define(_CLIENT_VERSION_RC, 0)
define(_CLIENT_VERSION_IS_RELEASE, true)
Expand Down
1 change: 1 addition & 0 deletions src/chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
static constexpr int64_t MAX_FUTURE_BLOCK_TIME = 2 * 60 * 60;

static constexpr int64_t MAX_FUTURE_BLOCK_TIME_DAKOTACRESCENT = 5 * 60;
static constexpr int64_t MAX_FUTURE_BLOCK_TIME_EUNOSPAYA = 30;

/**
* Timestamp window used as a grace period by code that compares external
Expand Down
13 changes: 9 additions & 4 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ class CMainParams : public CChainParams {
consensus.EunosHeight = 894000; // 3rd June 2021
consensus.EunosSimsHeight = consensus.EunosHeight;
consensus.EunosKampungHeight = 895743;
consensus.EunosPayaHeight = std::numeric_limits<int>::max();

consensus.pos.diffLimit = uint256S("00000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
// consensus.pos.nTargetTimespan = 14 * 24 * 60 * 60; // two weeks
Expand Down Expand Up @@ -345,6 +346,7 @@ class CTestNetParams : public CChainParams {
consensus.EunosHeight = 354950;
consensus.EunosSimsHeight = consensus.EunosHeight;
consensus.EunosKampungHeight = consensus.EunosHeight;
consensus.EunosPayaHeight = 463300;

consensus.pos.diffLimit = uint256S("00000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
// consensus.pos.nTargetTimespan = 14 * 24 * 60 * 60; // two weeks
Expand Down Expand Up @@ -522,9 +524,10 @@ class CDevNetParams : public CChainParams {
consensus.ClarkeQuayHeight = 0;
consensus.DakotaHeight = 10;
consensus.DakotaCrescentHeight = 10;
consensus.EunosHeight = 125;
consensus.EunosSimsHeight = 125;
consensus.EunosKampungHeight = 125;
consensus.EunosHeight = 150;
consensus.EunosSimsHeight = consensus.EunosHeight;
consensus.EunosKampungHeight = consensus.EunosHeight;
consensus.EunosPayaHeight = 300;

consensus.pos.diffLimit = uint256S("00000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
consensus.pos.nTargetTimespan = 5 * 60; // 5 min == 10 blocks
Expand Down Expand Up @@ -647,7 +650,7 @@ class CDevNetParams : public CChainParams {
vSeeds.clear();
// nodes with support for servicebits filtering should be at the top
// vSeeds.emplace_back("testnet-seed.defichain.io");
// vFixedSeeds = std::vector<SeedSpec6>(pnSeed6_test, pnSeed6_test + ARRAYLEN(pnSeed6_test));
vFixedSeeds = std::vector<SeedSpec6>(pnSeed6_devnet, pnSeed6_devnet + ARRAYLEN(pnSeed6_devnet));

fDefaultConsistencyChecks = false;
fRequireStandard = false;
Expand Down Expand Up @@ -697,6 +700,7 @@ class CRegTestParams : public CChainParams {
consensus.EunosHeight = 10000000;
consensus.EunosSimsHeight = 10000000;
consensus.EunosKampungHeight = 10000000;
consensus.EunosPayaHeight = 10000000;

consensus.pos.diffLimit = uint256S("00000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
consensus.pos.nTargetTimespan = 14 * 24 * 60 * 60; // two weeks
Expand Down Expand Up @@ -965,6 +969,7 @@ void CRegTestParams::UpdateActivationParametersFromArgs(const ArgsManager& args)
consensus.EunosHeight = static_cast<int>(height);
consensus.EunosSimsHeight = static_cast<int>(height);
consensus.EunosKampungHeight = static_cast<int>(height);
consensus.EunosPayaHeight = static_cast<int>(height);
}

if (!args.IsArgSet("-vbparams")) return;
Expand Down
4 changes: 4 additions & 0 deletions src/chainparamsseeds.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@ static SeedSpec6 pnSeed6_test[] = {
{{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x2d,0x38,0x48,0xc9}, 18555},
{{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xac,0x69,0x31,0x21}, 18555}
};

static SeedSpec6 pnSeed6_devnet[] = {
{{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x12,0xc5,0xa1,0x0e}, 20555}
};
#endif // DEFI_CHAINPARAMSSEEDS_H
1 change: 1 addition & 0 deletions src/consensus/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ struct Params {
int EunosHeight;
int EunosSimsHeight;
int EunosKampungHeight;
int EunosPayaHeight;
/** Foundation share after AMK, normalized to COIN = 100% */
CAmount foundationShareDFIP1;
/** Trackable burn address */
Expand Down
30 changes: 12 additions & 18 deletions src/masternodes/anchors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,6 @@ static const char DB_ANCHORS = 'A';
static const char DB_PENDING = 'p';
static const char DB_BITCOININDEX = 'Z'; // Bitcoin height to blockhash table

template <typename TContainer>
bool CheckSigs(uint256 const & sigHash, TContainer const & sigs, std::set<CKeyID> const & keys)
{
for (auto const & sig : sigs) {
CPubKey pubkey;
if (!pubkey.RecoverCompact(sigHash, sig) || keys.find(pubkey.GetID()) == keys.end())
return false;
}
return true;
}

uint256 CAnchorData::GetSignHash() const
{
CDataStream ss{SER_GETHASH, PROTOCOL_VERSION};
Expand Down Expand Up @@ -96,14 +85,20 @@ CAnchor CAnchor::Create(const std::vector<CAnchorAuthMessage> & auths, CTxDestin
return {};
}

bool CAnchor::CheckAuthSigs(CTeam const & team) const
bool CAnchor::CheckAuthSigs(CTeam const & team, const uint32_t height) const
{
// Sigs must meet quorum size.
if (sigs.size() < GetMinAnchorQuorum(team)) {
auto quorum = GetMinAnchorQuorum(team);
if (sigs.size() < quorum) {
return error("%s: Anchor auth team quorum not met. Min quorum: %d sigs size %d", __func__, GetMinAnchorQuorum(team), sigs.size());
}

return CheckSigs(GetSignHash(), sigs, team);
auto uniqueKeys = CheckSigs(GetSignHash(), sigs, team);
if (height >= Params().GetConsensus().EunosPayaHeight && uniqueKeys < quorum) {
return error("%s: Anchor auth team unique key quorum not met. Min quorum: %d keys size %d", __func__, GetMinAnchorQuorum(team), uniqueKeys);
}

return uniqueKeys;
}

const CAnchorAuthIndex::Auth * CAnchorAuthIndex::GetAuth(uint256 const & msgHash) const
Expand Down Expand Up @@ -550,8 +545,7 @@ void CAnchorIndex::CheckPendingAnchors()
}

// Validate the anchor sigs
CPubKey pubKey;
if (!rec.anchor.CheckAuthSigs(*anchorTeam)) {
if (!rec.anchor.CheckAuthSigs(*anchorTeam, anchorCreationHeight)) {
LogPrint(BCLog::ANCHORING, "Signature validation fails. Deleting anchor txHash %s\n", rec.txHash.ToString());
deletePending.insert(rec.txHash);
continue;
Expand Down Expand Up @@ -949,7 +943,7 @@ bool CAnchorFinalizationMessage::CheckConfirmSigs()
return CheckSigs(GetSignHash(), sigs, currentTeam);
}

bool CAnchorFinalizationMessagePlus::CheckConfirmSigs(const uint32_t height)
size_t CAnchorFinalizationMessagePlus::CheckConfirmSigs(const uint32_t height)
{
auto team = pcustomcsview->GetConfirmTeam(height);
if (!team) {
Expand Down Expand Up @@ -1078,7 +1072,7 @@ std::vector<CAnchorConfirmMessage> CAnchorAwaitingConfirms::GetQuorumFor(const C
for (auto it = list.begin(); it != list.end(); /* w/o advance! */) {
// get next group of confirms
KList::iterator it0, it1;
std::tie(it0,it1) = list.equal_range(std::make_tuple(it->btcTxHeight, it->GetSignHash()));
std::tie(it0,it1) = list.equal_range(std::make_tuple(it->btcTxHeight, it->btcTxHash));
if (std::distance(it0,it1) >= quorum) {
result.clear();
for (; result.size() < quorum && it0 != it1; ++it0) {
Expand Down
25 changes: 20 additions & 5 deletions src/masternodes/anchors.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class CAnchor : public CAnchorData
{}

static CAnchor Create(std::vector<CAnchorAuthMessage> const & auths, CTxDestination const & rewardDest);
bool CheckAuthSigs(CTeam const & team) const;
bool CheckAuthSigs(CTeam const & team, const uint32_t height) const;

ADD_SERIALIZE_METHODS;

Expand Down Expand Up @@ -433,7 +433,7 @@ struct CAnchorFinalizationMessagePlus : public CAnchorConfirmDataPlus
, sigs()
{}

bool CheckConfirmSigs(const uint32_t height);
size_t CheckConfirmSigs(const uint32_t height);

ADD_SERIALIZE_METHODS;

Expand Down Expand Up @@ -462,12 +462,13 @@ class CAnchorAwaitingConfirms
ordered_non_unique<
tag<Confirm::ByAnchor>, member<CAnchorConfirmData, uint256, &CAnchorConfirmData::btcTxHash>
>,
// index for quorum selection (miner affected)
// index for quorum selection (miner affected) Protected against double signing.
// just to remember that there may be confirms with equal btcTxHeight, but with different teams!
ordered_non_unique<
ordered_unique<
tag<Confirm::ByKey>, composite_key<Confirm,
member<CAnchorConfirmDataPlus, THeight, &CAnchorConfirmDataPlus::btcTxHeight>,
const_mem_fun<CAnchorConfirmDataPlus, uint256, &CAnchorConfirmDataPlus::GetSignHash>
member<CAnchorConfirmData, uint256, &CAnchorConfirmData::btcTxHash>,
const_mem_fun<Confirm, CKeyID, &Confirm::GetSigner>
>
>,
// restriction index that helps detect doublesigning
Expand Down Expand Up @@ -495,6 +496,20 @@ class CAnchorAwaitingConfirms
void ForEachConfirm(std::function<void(Confirm const &)> callback) const;
};

template <typename TContainer>
size_t CheckSigs(uint256 const & sigHash, TContainer const & sigs, std::set<CKeyID> const & keys)
{
std::set<CPubKey> uniqueKeys;
for (auto const & sig : sigs) {
CPubKey pubkey;
if (!pubkey.RecoverCompact(sigHash, sig) || keys.find(pubkey.GetID()) == keys.end())
return false;

uniqueKeys.insert(pubkey);
}
return uniqueKeys.size();
}

/// dummy, unknown consensus rules yet. may be additional params needed (smth like 'height')
/// even may be not here, but in CCustomCSView
uint32_t GetMinAnchorQuorum(CAnchorData::CTeam const & team);
Expand Down
37 changes: 36 additions & 1 deletion src/masternodes/icxorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const uint8_t CICXOrder::STATUS_EXPIRED = 3;
const std::string CICXOrder::CHAIN_BTC = "BTC";
const std::string CICXOrder::TOKEN_BTC = "BTC";

const uint32_t CICXMakeOffer::DEFAULT_EXPIRY = 10;
const uint32_t CICXMakeOffer::DEFAULT_EXPIRY = 20;
const uint32_t CICXMakeOffer::MAKER_DEPOSIT_REFUND_TIMEOUT = 100;
const uint8_t CICXMakeOffer::STATUS_OPEN = 0;
const uint8_t CICXMakeOffer::STATUS_CLOSED = 1;
Expand All @@ -47,15 +47,20 @@ const CAmount CICXMakeOffer::DEFAULT_TAKER_FEE_PER_BTC = AmountFromValue(0.003);

const uint32_t CICXSubmitDFCHTLC::MINIMUM_TIMEOUT = 500;
const uint32_t CICXSubmitDFCHTLC::MINIMUM_2ND_TIMEOUT = 250;
const uint32_t CICXSubmitDFCHTLC::EUNOSPAYA_MINIMUM_TIMEOUT = 1440;
const uint32_t CICXSubmitDFCHTLC::EUNOSPAYA_MINIMUM_2ND_TIMEOUT = 480;
const uint8_t CICXSubmitDFCHTLC::STATUS_OPEN = 0;
const uint8_t CICXSubmitDFCHTLC::STATUS_CLAIMED = 1;
const uint8_t CICXSubmitDFCHTLC::STATUS_REFUNDED = 2;
const uint8_t CICXSubmitDFCHTLC::STATUS_EXPIRED = 3;

const uint32_t CICXSubmitEXTHTLC::MINIMUM_TIMEOUT = 30;
const uint32_t CICXSubmitEXTHTLC::MINIMUM_2ND_TIMEOUT = 15;
const uint32_t CICXSubmitEXTHTLC::EUNOSPAYA_MINIMUM_TIMEOUT = 72;
const uint32_t CICXSubmitEXTHTLC::EUNOSPAYA_MINIMUM_2ND_TIMEOUT = 24;
// constant for calculating BTC block period in DFI block period per hour (BTC estimated to 6 blocks/h, DFI to 96 blocks/h)
const uint32_t CICXSubmitEXTHTLC::BTC_BLOCKS_IN_DFI_BLOCKS = 16;
const uint32_t CICXSubmitEXTHTLC::EUNOSPAYA_BTC_BLOCKS_IN_DFI_BLOCKS = 20;
const uint8_t CICXSubmitEXTHTLC::STATUS_OPEN = 0;
const uint8_t CICXSubmitEXTHTLC::STATUS_CLOSED = 1;
const uint8_t CICXSubmitEXTHTLC::STATUS_EXPIRED = 3;
Expand Down Expand Up @@ -295,6 +300,21 @@ std::unique_ptr<CICXOrderView::CICXSubmitDFCHTLCImpl> CICXOrderView::HasICXSubmi
return {};
}

bool CICXOrderView::ExistedICXSubmitDFCHTLC(uint256 const & offertxid, bool isPreEunosPaya)
{
bool result = false;

if (HasICXSubmitDFCHTLCOpen(offertxid))
result = true;
if (isPreEunosPaya)
return (result);
auto it = LowerBound<ICXSubmitDFCHTLCCloseKey>(TxidPairKey{offertxid, {}});
if (it.Valid() && it.Key().first == offertxid)
result = true;

return (result);
}

std::unique_ptr<CICXOrderView::CICXSubmitEXTHTLCImpl> CICXOrderView::GetICXSubmitEXTHTLCByCreationTx(const uint256 & txid) const
{
auto submitexthtlc = ReadBy<ICXSubmitEXTHTLCCreationTx,CICXSubmitEXTHTLCImpl>(txid);
Expand Down Expand Up @@ -358,6 +378,21 @@ std::unique_ptr<CICXOrderView::CICXSubmitEXTHTLCImpl> CICXOrderView::HasICXSubmi
return {};
}

bool CICXOrderView::ExistedICXSubmitEXTHTLC(uint256 const & offertxid, bool isPreEunosPaya)
{
bool result = false;

if (HasICXSubmitEXTHTLCOpen(offertxid))
result = true;
if (isPreEunosPaya)
return (result);
auto it = LowerBound<ICXSubmitEXTHTLCCloseKey>(TxidPairKey{offertxid, {}});
if (it.Valid() && it.Key().first == offertxid)
result = true;

return (result);
}

std::unique_ptr<CICXOrderView::CICXClaimDFCHTLCImpl> CICXOrderView::GetICXClaimDFCHTLCByCreationTx(uint256 const & txid) const
{
auto claimdfchtlc = ReadBy<ICXClaimDFCHTLCCreationTx,CICXClaimDFCHTLCImpl>(txid);
Expand Down
10 changes: 9 additions & 1 deletion src/masternodes/icxorder.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ class CICXSubmitDFCHTLC
{
public:
static const uint32_t MINIMUM_TIMEOUT; // minimum period in blocks after htlc automatically timeouts and funds are returned to owner when it is first htlc
static const uint32_t EUNOSPAYA_MINIMUM_TIMEOUT;
static const uint32_t MINIMUM_2ND_TIMEOUT; // minimum period in blocks after htlc automatically timeouts and funds are returned to owner when it is second htlc
static const uint32_t EUNOSPAYA_MINIMUM_2ND_TIMEOUT;
static const uint8_t STATUS_OPEN;
static const uint8_t STATUS_CLAIMED;
static const uint8_t STATUS_REFUNDED;
Expand All @@ -152,7 +154,7 @@ class CICXSubmitDFCHTLC
uint256 offerTx; // txid for which offer is this HTLC
CAmount amount = 0; // amount that is put in HTLC
uint256 hash; // hash for the hash lock part
uint32_t timeout = MINIMUM_TIMEOUT; // timeout (absolute in blocks) for timelock part
uint32_t timeout = 0; // timeout (absolute in blocks) for timelock part

ADD_SERIALIZE_METHODS;

Expand Down Expand Up @@ -195,8 +197,11 @@ class CICXSubmitEXTHTLC
{
public:
static const uint32_t MINIMUM_TIMEOUT; // default period in blocks after htlc timeouts when it is first htlc
static const uint32_t EUNOSPAYA_MINIMUM_TIMEOUT;
static const uint32_t MINIMUM_2ND_TIMEOUT; // default period in blocks after htlc timeouts when it is second htlc
static const uint32_t EUNOSPAYA_MINIMUM_2ND_TIMEOUT;
static const uint32_t BTC_BLOCKS_IN_DFI_BLOCKS; // number of BTC blocks in DFI blocks period
static const uint32_t EUNOSPAYA_BTC_BLOCKS_IN_DFI_BLOCKS; // number of BTC blocks in DFI blocks period
static const uint8_t STATUS_OPEN;
static const uint8_t STATUS_CLOSED;
static const uint8_t STATUS_EXPIRED;
Expand Down Expand Up @@ -413,6 +418,8 @@ class CICXOrderView : public virtual CStorageView {
void ForEachICXSubmitDFCHTLCClose(std::function<bool (TxidPairKey const &, uint8_t)> callback, uint256 const & offertxid = uint256());
void ForEachICXSubmitDFCHTLCExpire(std::function<bool (StatusKey const &, uint8_t)> callback, uint32_t const & height = 0);
std::unique_ptr<CICXSubmitDFCHTLCImpl> HasICXSubmitDFCHTLCOpen(uint256 const & offertxid);
bool ExistedICXSubmitDFCHTLC(uint256 const & offertxid, bool isPreEunosPaya);


//SubmitEXTHTLC
std::unique_ptr<CICXSubmitEXTHTLCImpl> GetICXSubmitEXTHTLCByCreationTx(uint256 const & txid) const;
Expand All @@ -422,6 +429,7 @@ class CICXOrderView : public virtual CStorageView {
void ForEachICXSubmitEXTHTLCClose(std::function<bool (TxidPairKey const &, uint8_t)> callback, uint256 const & offertxid = uint256());
void ForEachICXSubmitEXTHTLCExpire(std::function<bool (StatusKey const &, uint8_t)> callback, uint32_t const & height = 0);
std::unique_ptr<CICXSubmitEXTHTLCImpl> HasICXSubmitEXTHTLCOpen(uint256 const & offertxid);
bool ExistedICXSubmitEXTHTLC(uint256 const & offertxid, bool isPreEunosPaya);

//ClaimDFCHTLC
std::unique_ptr<CICXClaimDFCHTLCImpl> GetICXClaimDFCHTLCByCreationTx(uint256 const & txid) const;
Expand Down
Loading

0 comments on commit 4d93189

Please sign in to comment.