@@ -1324,6 +1324,11 @@ bool CCoinsViewCache::HandleSidechainEvents(int height, CBlockUndo& blockUndo, s
1324
1324
LogPrint (" sc" , " %s():%d - SIDECHAIN-EVENT: lastCertEpoch [%d], lastCertHash [%s]\n " ,
1325
1325
__func__, __LINE__, scInfo.lastEpochReferencedByCertificate , scInfo.lastCertificateHash .ToString ());
1326
1326
1327
+ blockUndo.vVoidedCertUndo .push_back (CVoidedCertUndo ());
1328
+ blockUndo.vVoidedCertUndo .back ().voidedCertScId = ceasingScId;
1329
+ LogPrint (" sc" , " %s():%d - set voidedCertHash[%s], ceasingScId = %s\n " ,
1330
+ __func__, __LINE__, scInfo.lastCertificateHash .ToString (), ceasingScId.ToString ());
1331
+
1327
1332
if (scInfo.lastEpochReferencedByCertificate == CScCertificate::EPOCH_NULL) {
1328
1333
assert (scInfo.lastCertificateHash .IsNull ());
1329
1334
continue ;
@@ -1336,19 +1341,8 @@ bool CCoinsViewCache::HandleSidechainEvents(int height, CBlockUndo& blockUndo, s
1336
1341
assert (coins->nBwtMaturityHeight != 0 );
1337
1342
1338
1343
// null all bwt outputs and add related txundo in block
1339
- bool foundFirstBwt = false ;
1340
-
1341
1344
for (int pos = coins->nFirstBwtPos ; pos < coins->vout .size (); ++pos)
1342
1345
{
1343
- if (!foundFirstBwt)
1344
- {
1345
- blockUndo.vVoidedCertUndo .push_back (CVoidedCertUndo ());
1346
- blockUndo.vVoidedCertUndo .back ().voidedCertScId = ceasingScId;
1347
- LogPrint (" sc" , " %s():%d - set voidedCertHash[%s], firstBwtPos[%d]\n " ,
1348
- __func__, __LINE__, scInfo.lastCertificateHash .ToString (), pos);
1349
- foundFirstBwt = true ;
1350
- }
1351
-
1352
1346
blockUndo.vVoidedCertUndo .back ().voidedOuts .push_back (CTxInUndo (coins->vout .at (pos)));
1353
1347
coins->Spend (pos);
1354
1348
if (coins->vout .size () == 0 )
@@ -1427,42 +1421,47 @@ bool CCoinsViewCache::RevertSidechainEvents(const CBlockUndo& blockUndo, int hei
1427
1421
1428
1422
CSidechain scInfo;
1429
1423
assert (GetSidechain (voidedCertUndo.voidedCertScId , scInfo));
1430
- const uint256& coinHash = scInfo.lastCertificateHash ;
1431
1424
1432
- if (coinHash.IsNull ())
1433
- {
1434
- fClean = fClean && error (" %s: malformed undo data, missing voided certificate hash " , __func__);
1435
- return fClean ;
1436
- }
1437
- LogPrint (" sc" , " %s():%d - reverting voiding of bwt for certificate [%s]\n " , __func__, __LINE__, coinHash.ToString ());
1438
1425
1439
- CCoinsModifier coins = this ->ModifyCoins (coinHash);
1440
- const std::vector<CTxInUndo>& voidedOuts = voidedCertUndo.voidedOuts ;
1441
- for (size_t idx = voidedOuts.size (); idx-- > 0 ;)
1426
+ if (scInfo.lastEpochReferencedByCertificate != CScCertificate::EPOCH_NULL)
1442
1427
{
1443
- if (voidedOuts.at (idx).nHeight != 0 )
1428
+ const uint256& coinHash = scInfo.lastCertificateHash ;
1429
+
1430
+ if (coinHash.IsNull ())
1444
1431
{
1445
- coins->fCoinBase = voidedOuts.at (idx).fCoinBase ;
1446
- coins->nHeight = voidedOuts.at (idx).nHeight ;
1447
- coins->nVersion = voidedOuts.at (idx).nVersion ;
1448
- coins->nFirstBwtPos = voidedOuts.at (idx).nFirstBwtPos ;
1449
- coins->nBwtMaturityHeight = voidedOuts.at (idx).nBwtMaturityHeight ;
1450
- } else
1432
+ fClean = fClean && error (" %s: malformed undo data, missing voided certificate hash " , __func__);
1433
+ return fClean ;
1434
+ }
1435
+ LogPrint (" sc" , " %s():%d - reverting voiding of bwt for certificate [%s]\n " , __func__, __LINE__, coinHash.ToString ());
1436
+
1437
+ CCoinsModifier coins = this ->ModifyCoins (coinHash);
1438
+ const std::vector<CTxInUndo>& voidedOuts = voidedCertUndo.voidedOuts ;
1439
+ for (size_t idx = voidedOuts.size (); idx-- > 0 ;)
1451
1440
{
1452
- if (coins->IsPruned ())
1453
- fClean = fClean && error (" %s: undo data adding output to missing transaction" , __func__);
1441
+ if (voidedOuts.at (idx).nHeight != 0 )
1442
+ {
1443
+ coins->fCoinBase = voidedOuts.at (idx).fCoinBase ;
1444
+ coins->nHeight = voidedOuts.at (idx).nHeight ;
1445
+ coins->nVersion = voidedOuts.at (idx).nVersion ;
1446
+ coins->nFirstBwtPos = voidedOuts.at (idx).nFirstBwtPos ;
1447
+ coins->nBwtMaturityHeight = voidedOuts.at (idx).nBwtMaturityHeight ;
1448
+ } else
1449
+ {
1450
+ if (coins->IsPruned ())
1451
+ fClean = fClean && error (" %s: undo data adding output to missing transaction" , __func__);
1452
+ }
1453
+
1454
+ if (coins->IsAvailable (coins->nFirstBwtPos + idx))
1455
+ fClean = fClean && error (" %s: undo data overwriting existing output" , __func__);
1456
+ if (coins->vout .size () < (coins->nFirstBwtPos + idx+1 ))
1457
+ coins->vout .resize (coins->nFirstBwtPos + idx+1 );
1458
+ coins->vout .at (coins->nFirstBwtPos + idx) = voidedOuts.at (idx).txout ;
1454
1459
}
1455
-
1456
- if (coins->IsAvailable (coins->nFirstBwtPos + idx))
1457
- fClean = fClean && error (" %s: undo data overwriting existing output" , __func__);
1458
- if (coins->vout .size () < (coins->nFirstBwtPos + idx+1 ))
1459
- coins->vout .resize (coins->nFirstBwtPos + idx+1 );
1460
- coins->vout .at (coins->nFirstBwtPos + idx) = voidedOuts.at (idx).txout ;
1460
+
1461
+ if (pVoidedCertsList != nullptr )
1462
+ pVoidedCertsList->push_back (coinHash);
1461
1463
}
1462
1464
1463
- if (pVoidedCertsList != nullptr )
1464
- pVoidedCertsList->push_back (coinHash);
1465
-
1466
1465
if (!fClean ) return false ;
1467
1466
1468
1467
recreatedScEvent.ceasingScs .insert (voidedCertUndo.voidedCertScId );
0 commit comments