Start of the proposal defer/playback code.

Clean up tem codes to tap codes.
This commit is contained in:
JoelKatz
2012-08-30 11:43:20 -07:00
parent 651cee5738
commit faaedb806f
7 changed files with 41 additions and 14 deletions

View File

@@ -299,6 +299,7 @@ void LedgerConsensus::handleLCL(const uint256& lclHash)
mCloseResolution = ContinuousLedgerTiming::getNextLedgerTimeResolution(
mPreviousLedger->getCloseResolution(), mPreviousLedger->getCloseAgree(),
mPreviousLedger->getLedgerSeq() + 1);
playbackProposals();
}
void LedgerConsensus::takeInitialPosition(Ledger& initialLedger)
@@ -810,10 +811,24 @@ void LedgerConsensus::Saccept(boost::shared_ptr<LedgerConsensus> This, SHAMap::p
This->accept(txSet);
}
void LedgerConsensus::deferProposal(const LedgerProposal::pointer& proposal, const NewcoinAddress& peerPublic)
{
/**/
}
void LedgerConsensus::playbackProposals()
{
for ( boost::unordered_map< uint160, std::list<LedgerProposal::pointer> >::iterator
it = mDeferredProposals.begin(), end = mDeferredProposals.end(); it != end; ++it)
{
/**/
}
}
void LedgerConsensus::applyTransaction(TransactionEngine& engine, const SerializedTransaction::pointer& txn,
const Ledger::pointer& ledger, CanonicalTXSet& failedTransactions, bool openLedger)
{
TransactionEngineParams parms = openLedger ? temOPEN_LEDGER : temFINAL;
TransactionEngineParams parms = openLedger ? tapOPEN_LEDGER : tapNONE;
#ifndef TRUST_NETWORK
try
{
@@ -846,7 +861,7 @@ void LedgerConsensus::applyTransaction(TransactionEngine& engine, const Serializ
void LedgerConsensus::applyTransactions(const SHAMap::pointer& set, const Ledger::pointer& applyLedger,
const Ledger::pointer& checkLedger, CanonicalTXSet& failedTransactions, bool openLgr)
{
TransactionEngineParams parms = openLgr ? temOPEN_LEDGER : temFINAL;
TransactionEngineParams parms = openLgr ? tapOPEN_LEDGER : tapNONE;
TransactionEngine engine(applyLedger);
for (SHAMapItem::pointer item = set->peekFirstItem(); !!item; item = set->peekNextItem(item->getTag()))

View File

@@ -111,6 +111,9 @@ protected:
// Close time estimates
std::map<uint32, int> mCloseTimes;
// deferred proposals (node ID -> proposals from that peer)
boost::unordered_map< uint160, std::list<LedgerProposal::pointer> > mDeferredProposals;
// final accept logic
static void Saccept(boost::shared_ptr<LedgerConsensus> This, SHAMap::pointer txSet);
void accept(const SHAMap::pointer& txSet);
@@ -136,6 +139,7 @@ protected:
void statusChange(newcoin::NodeEvent, Ledger& ledger);
void takeInitialPosition(Ledger& initialLedger);
void updateOurPositions();
void playbackProposals();
int getThreshold();
void beginAccept();
void endConsensus();
@@ -167,6 +171,7 @@ public:
bool haveConsensus();
bool peerPosition(const LedgerProposal::pointer&);
void deferProposal(const LedgerProposal::pointer& proposal, const NewcoinAddress& peerPublic);
bool peerHasSet(const Peer::pointer& peer, const uint256& set, newcoin::TxSetStatus status);

View File

@@ -84,7 +84,7 @@ Transaction::pointer NetworkOPs::processTransaction(Transaction::pointer trans,
return trans;
}
TER r = mLedgerMaster->doTransaction(*trans->getSTransaction(), tgtLedger, temOPEN_LEDGER);
TER r = mLedgerMaster->doTransaction(*trans->getSTransaction(), tgtLedger, tapOPEN_LEDGER);
if (r == tefFAILURE) throw Fault(IO_ERROR);
if (r == terPRE_SEQ)
@@ -599,7 +599,7 @@ int NetworkOPs::beginConsensus(const uint256& networkClosed, Ledger::pointer clo
// <-- bool: true to relay
bool NetworkOPs::recvPropose(uint32 proposeSeq, const uint256& proposeHash, uint32 closeTime,
const std::string& pubKey, const std::string& signature)
const std::string& pubKey, const std::string& signature, const NewcoinAddress& nodePublic)
{
// JED: does mConsensus need to be locked?
@@ -638,6 +638,8 @@ bool NetworkOPs::recvPropose(uint32 proposeSeq, const uint256& proposeHash, uint
if (!proposal->checkSign(signature))
{ // Note that if the LCL is different, the signature check will fail
Log(lsWARNING) << "Ledger proposal fails signature check";
if ((mMode != omFULL) && (mMode != omTRACKING) && theApp->getUNL().nodeInUNL(proposal->peekPublic()))
mConsensus->deferProposal(proposal, nodePublic);
return false;
}

View File

@@ -160,7 +160,7 @@ public:
// ledger proposal/close functions
bool recvPropose(uint32 proposeSeq, const uint256& proposeHash, uint32 closeTime,
const std::string& pubKey, const std::string& signature);
const std::string& pubKey, const std::string& signature, const NewcoinAddress& nodePublic);
bool gotTXData(const boost::shared_ptr<Peer>& peer, const uint256& hash,
const std::list<SHAMapNode>& nodeIDs, const std::list< std::vector<unsigned char> >& nodeData);
bool recvValidation(const SerializedValidation::pointer& val);

View File

@@ -726,7 +726,7 @@ void Peer::recvPropose(newcoin::TMProposeSet& packet)
memcpy(currentTxHash.begin(), packet.currenttxhash().data(), 32);
if(theApp->getOPs().recvPropose(proposeSeq, currentTxHash, packet.closetime(),
packet.nodepubkey(), packet.signature()))
packet.nodepubkey(), packet.signature(), mNodePublic))
{ // FIXME: Not all nodes will want proposals
PackedMessage::pointer message = boost::make_shared<PackedMessage>(packet, newcoin::mtPROPOSE_LEDGER);
theApp->getConnectionPool().relayMessage(this, message);

View File

@@ -973,7 +973,7 @@ TER TransactionEngine::applyTransaction(const SerializedTransaction& txn,
naSigningPubKey = NewcoinAddress::createAccountPublic(txn.peekSigningPubKey());
// Consistency: really signed.
if ((tesSUCCESS == terResult) && ((params & temNO_CHECK_SIGN) == 0) && !txn.checkSign(naSigningPubKey))
if ((tesSUCCESS == terResult) && ((params & tapNO_CHECK_SIGN) == 0) && !txn.checkSign(naSigningPubKey))
{
Log(lsWARNING) << "applyTransaction: Invalid transaction: bad signature";
@@ -1032,7 +1032,7 @@ TER TransactionEngine::applyTransaction(const SerializedTransaction& txn,
STAmount saPaid = txn.getTransactionFee();
if (tesSUCCESS == terResult && (params & temOPEN_LEDGER) != temNONE)
if (tesSUCCESS == terResult && (params & tapOPEN_LEDGER) != tapNONE)
{ // Applying to open ledger, check fee
if (!!saCost)
{
@@ -1322,7 +1322,7 @@ TER TransactionEngine::applyTransaction(const SerializedTransaction& txn,
if (!mLedger->addTransaction(txID, s))
assert(false);
if ((params & temOPEN_LEDGER) == temNONE)
if ((params & tapOPEN_LEDGER) == tapNONE)
mLedger->destroyCoins(saPaid.getNValue());
}

View File

@@ -93,11 +93,16 @@ bool transResultInfo(TER terCode, std::string& strToken, std::string& strHuman);
enum TransactionEngineParams
{
temNONE = 0x00,
temNO_CHECK_SIGN = 0x01, // Signature already checked
temOPEN_LEDGER = 0x10, // Transaction is running against an open ledger
temRETRY_OK = 0x20, // It was voted into a ledger anyway
temFINAL = 0x40, // This may be the transaction's last pass
tapNONE = 0x00,
tapNO_CHECK_SIGN = 0x01, // Signature already checked
tapOPEN_LEDGER = 0x10, // Transaction is running against an open ledger
// true = failures are not forwarded, check transaction fee
// false = debit ledger for consumed funds
tapRETRY = 0x20, // This is not the transaction's last pass
// Transaction can be retried, soft failures allowed
};
typedef struct {