With all this rope lying about, someone might get hung.

(Wrong length for SerialializedTransaction.)
This commit is contained in:
JoelKatz
2012-06-01 16:25:59 -07:00
parent d5100c1266
commit 9d41104d83
6 changed files with 19 additions and 10 deletions

View File

@@ -9,6 +9,8 @@
#include "SerializedValidation.h"
#include "Log.h"
#define TRUST_NETWORK
TransactionAcquire::TransactionAcquire(const uint256& hash) : PeerSet(hash, 1), mHaveRoot(false)
{
mMap = boost::make_shared<SHAMap>();
@@ -525,7 +527,8 @@ bool LedgerConsensus::peerPosition(LedgerProposal::pointer newPosition)
return true;
}
}
Log(lsINFO) << "Peer changes position";
Log(lsINFO) << "Peer position " << newPosition->getProposeSeq() << "/"
<< newPosition->getCurrentHash().GetHex();
currentPosition = newPosition;
SHAMap::pointer set = getTransactionTree(newPosition->getCurrentHash(), true);
if (set)
@@ -595,10 +598,12 @@ void LedgerConsensus::applyTransactions(SHAMap::pointer set, Ledger::pointer led
while (item)
{
Log(lsINFO) << "Processing candidate transaction: " << item->getTag().GetHex();
#ifndef TRUST_NETWORK
try
{
#endif
SerializerIterator sit(item->peekSerializer());
SerializedTransaction::pointer txn = boost::make_shared<SerializedTransaction>(boost::ref(sit), 0);
SerializedTransaction::pointer txn = boost::make_shared<SerializedTransaction>(boost::ref(sit));
TransactionEngineResult result = engine.applyTransaction(*txn, tepNO_CHECK_FEE);
if (result > 0)
{
@@ -616,11 +621,13 @@ void LedgerConsensus::applyTransactions(SHAMap::pointer set, Ledger::pointer led
Log(lsINFO) << " hard fail";
assert(!ledger->hasTransaction(item->getTag()));
}
#ifndef TRUST_NETWORK
}
catch (...)
{
Log(lsWARNING) << " Throws";
}
#endif
item = set->peekNextItem(item->getTag());
}

View File

@@ -580,7 +580,7 @@ void Peer::recvTransaction(newcoin::TMTransaction& packet)
std::string rawTx = packet.rawtransaction();
Serializer s(std::vector<unsigned char>(rawTx.begin(), rawTx.end()));
SerializerIterator sit(s);
SerializedTransaction::pointer stx = boost::make_shared<SerializedTransaction>(boost::ref(sit), -1);
SerializedTransaction::pointer stx = boost::make_shared<SerializedTransaction>(boost::ref(sit));
tx = boost::make_shared<Transaction>(stx, true);
if (tx->getStatus() == INVALID) throw(0);

View File

@@ -17,12 +17,14 @@ SerializedTransaction::SerializedTransaction(TransactionType type) : mType(type)
mInnerTxn = STObject(mFormat->elements, "InnerTransaction");
}
SerializedTransaction::SerializedTransaction(SerializerIterator& sit, int length)
SerializedTransaction::SerializedTransaction(SerializerIterator& sit)
{
if (length == -1) length = sit.getBytesLeft();
else if (length == 0) length = sit.get32();
int length = sit.getBytesLeft();
if ((length < TransactionMinLen) || (length > TransactionMaxLen))
{
Log(lsERROR) << "Transaction has invalid length: " << length;
throw std::runtime_error("Transaction length invalid");
}
mSignature.setValue(sit.getVL());

View File

@@ -26,7 +26,7 @@ protected:
SerializedTransaction* duplicate() const { return new SerializedTransaction(*this); }
public:
SerializedTransaction(SerializerIterator& sit, int length); // -1=all remaining, 0=get from sit
SerializedTransaction(SerializerIterator& sit);
SerializedTransaction(TransactionType type);
// STObject functions

View File

@@ -37,7 +37,7 @@ Transaction::pointer Transaction::sharedTransaction(const std::vector<unsigned c
Serializer s(vucTransaction);
SerializerIterator sit(s);
SerializedTransaction::pointer st = boost::make_shared<SerializedTransaction>(boost::ref(sit), -1);
SerializedTransaction::pointer st = boost::make_shared<SerializedTransaction>(boost::ref(sit));
return boost::make_shared<Transaction>(st, bValidate);
}
@@ -396,7 +396,7 @@ Transaction::pointer Transaction::transactionFromSQL(const std::string& sql)
Serializer s(rawTxn);
SerializerIterator it(s);
SerializedTransaction::pointer txn = boost::make_shared<SerializedTransaction>(boost::ref(it), -1);
SerializedTransaction::pointer txn = boost::make_shared<SerializedTransaction>(boost::ref(it));
Transaction::pointer tr = boost::make_shared<Transaction>(txn, true);
TransStatus st(INVALID);

View File

@@ -241,7 +241,7 @@ TransactionEngineResult TransactionEngine::applyTransaction(const SerializedTran
Serializer ser;
txn.add(ser);
SerializerIterator sit(ser);
SerializedTransaction s2(sit, -1);
SerializedTransaction s2(sit);
if (!s2.isEquivalent(txn))
{
std::cerr << "Transaction serdes mismatch" << std::endl;