Skip to content

Commit

Permalink
Testnet and identity lock fix
Browse files Browse the repository at this point in the history
  • Loading branch information
miketout committed Apr 19, 2024
1 parent 2162221 commit 3327395
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 9 deletions.
7 changes: 7 additions & 0 deletions src/pbaas/identity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,13 @@ CIdentity::GetIdentityContentByKey(const uint160 &idID,
return retVec;
}

bool CIdentity::IsLocked(uint32_t height) const
{
return nVersion >= VERSION_VAULT &&
(IsLocked() || (!ConnectedChains.IdentityLockOverride(*this, height) && unlockAfter >= height)) &&
!IsRevoked();
}

CIdentity CIdentity::LookupIdentity(const std::string &name, uint32_t height, uint32_t *pHeightOut, CTxIn *idTxIn)
{
return LookupIdentity(GetID(name), height, pHeightOut, idTxIn);
Expand Down
13 changes: 7 additions & 6 deletions src/pbaas/identity.h
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,12 @@ class CIdentity : public CPrincipal
}
}

void ClearLock()
{
flags &= ~FLAG_LOCKED;
unlockAfter = 0;
}

// This only returns the state of the lock flag. Note that an ID stays locked from spending or
// signing until the height it was unlocked plus the time lock applied when it was locked.
bool IsLocked() const
Expand All @@ -686,12 +692,7 @@ class CIdentity : public CPrincipal
// consider the unlockAfter height as well
// this continues to return that it is locked after it is unlocked
// until passed the parameter of the height at which it was unlocked, plus the time lock
bool IsLocked(uint32_t height) const
{
return nVersion >= VERSION_VAULT &&
(IsLocked() || unlockAfter >= height) &&
!IsRevoked();
}
bool IsLocked(uint32_t height) const;

int32_t UnlockHeight() const
{
Expand Down
52 changes: 49 additions & 3 deletions src/pbaas/pbaas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3169,7 +3169,8 @@ bool ValidateReserveDeposit(struct CCcontract_info *cp, Eval* eval, const CTrans
bool isUpdatedConversion = ConnectedChains.CheckZeroViaOnlyPostLaunch(nHeight);

int32_t transitionBlocks = (PBAAS_TESTMODE ? ((24 * 60 * 60) / ConnectedChains.ThisChain().blockTime) : 100);
bool clearConvertTransition = destCurDef.IsFractional() &&
bool clearConvertTransition = IsVerusMainnetActive() &&
destCurDef.IsFractional() &&
!ConnectedChains.CheckClearConvert(std::max(((int32_t)nHeight) - transitionBlocks, 1)) &&
ConnectedChains.CheckClearConvert(nHeight);

Expand Down Expand Up @@ -6492,7 +6493,18 @@ bool CConnectedChains::DiscernBlockOneLaunchInfo(uint32_t height) const

bool CConnectedChains::CheckClearConvert(uint32_t height) const
{
return (!PBAAS_TESTMODE && (!IsVerusActive() || height >= PBAAS_CLEARCONVERT_HEIGHT));
if (!IsVerusActive())
{
return true;
}
if (IsVerusMainnetActive())
{
return height >= PBAAS_CLEARCONVERT_HEIGHT;
}
// TODO: TESTNET RESET - remove these exception heights
// testnet exception heights to prevent testnet reset
static std::set<uint32_t> pendingTestnetExportHeights({5723, 5724, 5751, 5752, 5757, 5758, 5770, 5771, 6229, 6230, 6431, 6432, 7014, 7015, 7048, 7049, 7078, 7079, 7593, 7594, 7633, 7634, 7635, 7636});
return height >= 8330 || pendingTestnetExportHeights.count(height);
}

uint32_t CConnectedChains::AutoArbitrageEnabledHeight(bool getVerusHeight) const
Expand Down Expand Up @@ -6538,6 +6550,38 @@ bool CConnectedChains::ForceIdentityUpgrade(uint32_t height) const
return false;
}

#define FORCE_IDENTITY_UNLOCK_HEIGHT 67000

bool CConnectedChains::ForceIdentityUnlock(uint32_t height) const
{
if (vARRRChainID() != ASSETCHAINS_CHAINID || height >= FORCE_IDENTITY_UNLOCK_HEIGHT)
{
return true;
}

auto iiuIt = ConnectedChains.activeUpgradesByKey.find(ConnectedChains.ForceIdentityUnlockKey());
if (iiuIt != ConnectedChains.activeUpgradesByKey.end() &&
height >= iiuIt->second.upgradeBlockHeight)
{
return true;
}

return false;
}

bool CConnectedChains::IdentityLockOverride(const CIdentity &identity, uint32_t height) const
{
if (identity.unlockAfter > 800000 &&
ASSETCHAINS_CHAINID == ConnectedChains.vARRRChainID() &&
ForceIdentityUnlock(height) &&
height < (FORCE_IDENTITY_UNLOCK_HEIGHT + 10000))
{
static std::set<CIdentityID> exemptIDs({GetDestinationID(DecodeDestination("iSXF8KbbvpHDWBm4zHxeA4n7uc1LsfR15X")), GetDestinationID(DecodeDestination("i4UxDzYtNR5oeGEEVritXuzAKjKzoVgiPK")), GetDestinationID(DecodeDestination("i5nQeKAWmxaXdNYv36qLQzz6XV8gZEqbaV"))});
return exemptIDs.count(identity.GetID());
}
return false;
}

bool CConnectedChains::ConfigureEthBridge(bool callToCheck)
{
// first time through, we initialize the VETH gateway config file
Expand Down Expand Up @@ -7930,6 +7974,7 @@ bool CConnectedChains::CreateLatestImports(const CCurrencyDefinition &sourceSyst
lastNotarization.ToUniValue().write(1,2).c_str(),
nextHeight,
EntropyHashFromHeight(CBlockIndex::BlockEntropyKey(), nextHeight, lastNotarization.currencyID).GetHex().c_str());
LogPrint("crosschainimports", "Expected next notarization %s\n", newNotarization.ToUniValue().write(1,2).c_str());
}

// after the last clear launch export is imported, we have completed launch
Expand Down Expand Up @@ -7957,7 +8002,8 @@ bool CConnectedChains::CreateLatestImports(const CCurrencyDefinition &sourceSyst
}

int32_t transitionBlocks = (PBAAS_TESTMODE ? ((24 * 60 * 60) / ConnectedChains.ThisChain().blockTime) : 100) - 1;
bool clearConvertTransition = destCur.IsFractional() &&
bool clearConvertTransition = IsVerusMainnetActive() &&
destCur.IsFractional() &&
!ConnectedChains.CheckClearConvert(std::max(((int32_t)nHeight) - transitionBlocks, 1)) &&
ConnectedChains.CheckClearConvert(nHeight + 1) &&
!ConnectedChains.CheckClearConvert(lastNotarization.notarizationHeight) && ConnectedChains.CheckClearConvert(nHeight);
Expand Down
14 changes: 14 additions & 0 deletions src/pbaas/pbaas.h
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,8 @@ class CConnectedChains
bool vARRRUpdateEnabled(uint32_t height) const;
uint160 vARRRChainID() const;
bool ForceIdentityUpgrade(uint32_t height) const;
bool ForceIdentityUnlock(uint32_t height) const;
bool IdentityLockOverride(const CIdentity &identity, uint32_t height) const;

std::vector<CCurrencyDefinition> GetMergeMinedChains()
{
Expand Down Expand Up @@ -1319,6 +1321,18 @@ class CConnectedChains
return key;
}

static std::string ForceIdentityUnlockKeyName()
{
return "vrsc::system.upgradedata.forceidentityunlock";
}

static uint160 ForceIdentityUnlockKey()
{
static uint160 nameSpace;
static uint160 key = CVDXF_Data::GetDataKey(ForceIdentityUnlockKeyName(), nameSpace);
return key;
}

static std::string DisablePBaaSCrossChainKeyName()
{
return "vrsc::system.upgradedata.disablepbaascrosschain";
Expand Down
7 changes: 7 additions & 0 deletions src/pbaas/reserves.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3894,6 +3894,13 @@ bool CReserveTransfer::GetTxOut(const CCurrencyDefinition &sourceSystem,
importedID.UpgradeVersion(height);
}

if (ConnectedChains.ForceIdentityUnlock(height) &&
!importedID.IsLocked() &&
importedID.IsLocked(height))
{
importedID.ClearLock();
}

// check for collisions and if not present, make an ID output
bool idCollision = false, currencyCollision = false;

Expand Down

0 comments on commit 3327395

Please sign in to comment.