Logic to 'rebase' a ledger to a different previous ledger.

This code does not assume the new previous ledger is valid
or trusted.
1) Validate sequence numbers and basic information.
2) Create a new ledger based on the new previous ledger.
3) Compare the old previous ledger and the new previous
ledger.
4) Try to include any missing, valid transactions in
the current ledger.
5) Traverse the old ledger based on the old previous ledger,
try to import any transactions into the new ledger.
This commit is contained in:
JoelKatz
2012-01-24 21:30:27 -08:00
parent b5afbf52ec
commit f4e6a72e1c
5 changed files with 77 additions and 12 deletions

View File

@@ -274,12 +274,10 @@ Transaction::pointer Transaction::findFrom(const uint160& fromID, uint32 seq)
}
bool Transaction::convertToTransactions(uint32 firstLedgerSeq, uint32 secondLedgerSeq,
bool checkFirstTransactions, bool checkSecondTransactions,
const std::map<uint256, std::pair<SHAMapItem::pointer, SHAMapItem::pointer> >& inMap,
bool checkFirstTransactions, bool checkSecondTransactions, const SHAMap::SHAMapDiff& inMap,
std::map<uint256, std::pair<Transaction::pointer, Transaction::pointer> >& outMap)
{ // convert a straight SHAMap payload difference to a transaction difference table
// return value: true=ledgers are valid, false=a ledger is invalid
bool ret=true;
std::map<uint256, std::pair<SHAMapItem::pointer, SHAMapItem::pointer> >::const_iterator it;
for(it=inMap.begin(); it!=inMap.end(); ++it)
{
@@ -294,7 +292,7 @@ bool Transaction::convertToTransactions(uint32 firstLedgerSeq, uint32 secondLedg
if( (firstTrans->getStatus()==INVALID) || (firstTrans->getID()!=id) )
{
firstTrans->setStatus(INVALID, firstLedgerSeq);
ret=false;
return false;
}
else firstTrans->setStatus(INCLUDED, firstLedgerSeq);
}
@@ -305,17 +303,17 @@ bool Transaction::convertToTransactions(uint32 firstLedgerSeq, uint32 secondLedg
if( (secondTrans->getStatus()==INVALID) || (secondTrans->getID()!=id) )
{
secondTrans->setStatus(INVALID, secondLedgerSeq);
ret=false;
return false;
}
else secondTrans->setStatus(INCLUDED, secondLedgerSeq);
}
assert(firstTrans || secondTrans);
if(firstTrans && secondTrans && (firstTrans->getStatus()!=INVALID) && (secondTrans->getStatus()!=INVALID))
ret=false; // one or the other SHAMap is structurally invalid or a miracle has happened
return false; // one or the other SHAMap is structurally invalid or a miracle has happened
outMap[id]=std::pair<Transaction::pointer, Transaction::pointer>(firstTrans, secondTrans);
}
return ret;
return true;
}
static bool isHex(char j)