Skip to content

Commit

Permalink
SKALED-1719 More prettifying
Browse files Browse the repository at this point in the history
  • Loading branch information
dimalit committed Apr 17, 2024
1 parent 66db975 commit bc9cd39
Show file tree
Hide file tree
Showing 14 changed files with 108 additions and 197 deletions.
4 changes: 2 additions & 2 deletions libethcore/TransactionBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ class TransactionBase {
bool isCreation() const { return m_type == ContractCreation; }

/// @returns the RLP serialisation of this transaction.
bytes rlp( IncludeSignature _sig = WithSignature ) const {
bytes toBytes( IncludeSignature _sig = WithSignature, bool _forEip155hash = false ) const {
RLPStream s;
streamRLP( s, _sig );
streamRLP( s, _sig, _forEip155hash );
bytes output = s.out();
if ( m_txType != TransactionType::Legacy )
output.insert( output.begin(), m_txType );
Expand Down
2 changes: 1 addition & 1 deletion libethereum/Block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,7 @@ void Block::commitToSeal(
receipt( i ).streamRLP( receiptrlp );
receiptsMap.insert( std::make_pair( k.out(), receiptrlp.out() ) );

dev::bytes txOutput = m_transactions[i].rlp();
dev::bytes txOutput = m_transactions[i].toBytes();
if ( m_transactions[i].txType() != dev::eth::TransactionType::Legacy ) {
RLPStream s;
s.append( txOutput );
Expand Down
6 changes: 3 additions & 3 deletions libethereum/SkaleHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ ConsensusExtFace::transactions_vector SkaleHost::pendingTransactions(
m_m_transaction_cache[sha.asArray()] = txn;
}

out_vector.push_back( txn.rlp() );
out_vector.push_back( txn.toBytes() );

++total_sent;

Expand Down Expand Up @@ -892,7 +892,7 @@ void SkaleHost::broadcastFunc() {
if ( !m_broadcastPauseFlag ) {
MICROPROFILE_SCOPEI(
"SkaleHost", "broadcastFunc.broadcast", MP_CHARTREUSE1 );
std::string rlp = toJS( txn.rlp() );
std::string rlp = toJS( txn.toBytes() );
std::string h = toJS( txn.sha3() );
//
std::string strPerformanceQueueName = "bc/broadcast";
Expand Down Expand Up @@ -995,7 +995,7 @@ void SkaleHost::forceEmptyBlock() {
}

void SkaleHost::forcedBroadcast( const Transaction& _txn ) {
m_broadcaster->broadcast( toJS( _txn.rlp() ) );
m_broadcaster->broadcast( toJS( _txn.toBytes() ) );
}

void SkaleHost::noteNewTransactions() {}
Expand Down
16 changes: 8 additions & 8 deletions libethereum/TransactionQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ ImportResult TransactionQueue::import(
// if( t == fs->second.begin() ){
UpgradeGuard ul( l );
--m_futureSize;
m_futureSizeBytes -= t->second.transaction.rlp().size();
m_futureSizeBytes -= t->second.transaction.toBytes().size();
auto erasedHash = t->second.transaction.sha3();
LOG( m_loggerDetail ) << "Re-inserting future transaction " << erasedHash;
m_known.erase( erasedHash );
Expand Down Expand Up @@ -327,7 +327,7 @@ void TransactionQueue::insertCurrent_WITH_LOCK( std::pair< h256, Transaction > c
inserted.first->second = handle;
m_currentByHash[_p.first] = handle;
#pragma GCC diagnostic pop
m_currentSizeBytes += t.rlp().size();
m_currentSizeBytes += t.toBytes().size();

// Move following transactions from future to current
makeCurrent_WITH_LOCK( t );
Expand All @@ -345,7 +345,7 @@ bool TransactionQueue::remove_WITH_LOCK( h256 const& _txHash ) {
auto it = m_currentByAddressAndNonce.find( from );
assert( it != m_currentByAddressAndNonce.end() );
it->second.erase( ( *t->second ).transaction.nonce() );
m_currentSizeBytes -= ( *t->second ).transaction.rlp().size();
m_currentSizeBytes -= ( *t->second ).transaction.toBytes().size();
m_current.erase( t->second );
m_currentByHash.erase( t );
if ( it->second.empty() )
Expand Down Expand Up @@ -382,8 +382,8 @@ void TransactionQueue::setFuture_WITH_LOCK( h256 const& _txHash ) {
*( m->second ) ); // set has only const iterators. Since we are moving out of container
// that's fine
m_currentByHash.erase( t.transaction.sha3() );
m_currentSizeBytes -= t.transaction.rlp().size();
m_futureSizeBytes += t.transaction.rlp().size();
m_currentSizeBytes -= t.transaction.toBytes().size();
m_futureSizeBytes += t.transaction.toBytes().size();
target.emplace( t.transaction.nonce(), move( t ) );
m_current.erase( m->second );
++m_futureSize;
Expand All @@ -396,7 +396,7 @@ void TransactionQueue::setFuture_WITH_LOCK( h256 const& _txHash ) {
// TODO: priority queue for future transactions
// For now just drop random chain end
--m_futureSize;
m_futureSizeBytes -= m_future.begin()->second.rbegin()->second.transaction.rlp().size();
m_futureSizeBytes -= m_future.begin()->second.rbegin()->second.transaction.toBytes().size();
auto erasedHash = m_future.begin()->second.rbegin()->second.transaction.sha3();
LOG( m_loggerDetail ) << "Dropping out of bounds future transaction " << erasedHash;
m_known.erase( erasedHash );
Expand Down Expand Up @@ -430,8 +430,8 @@ void TransactionQueue::makeCurrent_WITH_LOCK( Transaction const& _t ) {
inserted.first->second = handle;
m_currentByHash[( *handle ).transaction.sha3()] = handle;
#pragma GCC diagnostic pop
m_futureSizeBytes -= ( *handle ).transaction.rlp().size();
m_currentSizeBytes += ( *handle ).transaction.rlp().size();
m_futureSizeBytes -= ( *handle ).transaction.toBytes().size();
m_currentSizeBytes += ( *handle ).transaction.toBytes().size();
--m_futureSize;
++ft;
++nonce;
Expand Down
2 changes: 1 addition & 1 deletion libweb3jsonrpc/Eth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ Json::Value Eth::eth_signTransaction( Json::Value const& _json ) {
ts = client()->populateTransactionWithDefaults( ts );
pair< bool, Secret > ar = m_ethAccounts.authenticate( ts );
Transaction t( ts, ar.second ); // always legacy, no prefix byte
return toJson( t, t.rlp() );
return toJson( t, t.toBytes() );
} catch ( Exception const& ) {
throw JsonRpcException( exceptionToErrorMessage() );
}
Expand Down
4 changes: 2 additions & 2 deletions skale-key/KeyAux.h
Original file line number Diff line number Diff line change
Expand Up @@ -347,10 +347,10 @@ class KeyCLI {
t.sign( s );
cout << t.sha3() << ": ";
if ( isFile ) {
writeFile( i + ".signed", toHex( t.rlp() ) );
writeFile( i + ".signed", toHex( t.toBytes() ) );
cout << i + ".signed" << endl;
} else
cout << toHex( t.rlp() ) << endl;
cout << toHex( t.toBytes() ) << endl;
} catch ( Exception& ex ) {
cerr << "Invalid transaction: " << ex.what() << endl;
}
Expand Down
2 changes: 1 addition & 1 deletion test/tools/jsontests/BlockChainTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,7 @@ void checkBlocks(
BOOST_CHECK_MESSAGE( trField == trRlp,
_testname + "transactions from rlp and transaction from field do not match" );
BOOST_CHECK_MESSAGE(
trField.rlp() == trRlp.rlp(), _testname + "transactions rlp do not match" );
trField.toBytes() == trRlp.toBytes(), _testname + "transactions rlp do not match" );
}

vector< TestBlock > const& unclesFromField = _blockFromFields.uncles();
Expand Down
13 changes: 5 additions & 8 deletions test/tools/libtesteth/BlockChainHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ TestBlock::TestBlock( std::string const& _blockRLP ) : TestBlock() {
for ( auto const& tr : root[1] ) {
Transaction tx( tr.data(), CheckTransaction::Everything );
TestTransaction testTx( tx );
m_transactionQueue.import( tx.rlp() );
m_transactionQueue.import( tx.toBytes() );
m_testTransactions.push_back( testTx );
}

Expand Down Expand Up @@ -121,7 +121,7 @@ void TestBlock::setState( State const& _state ) {

void TestBlock::addTransaction( TestTransaction const& _tr ) {
m_testTransactions.push_back( _tr );
if ( m_transactionQueue.import( _tr.transaction().rlp() ) != ImportResult::Success )
if ( m_transactionQueue.import( _tr.transaction().toBytes() ) != ImportResult::Success )
cnote << TestOutputHelper::get().testName() + " Test block failed importing transaction\n";
recalcBlockHeaderBytes();
}
Expand Down Expand Up @@ -383,11 +383,8 @@ void TestBlock::recalcBlockHeaderBytes() {
txList.push_back( txi );
RLPStream txStream;
txStream.appendList( txList.size() );
for ( unsigned i = 0; i < txList.size(); ++i ) {
RLPStream txrlp;
txList[i].streamRLP( txrlp );
txStream.appendRaw( txrlp.out() );
}
for ( unsigned i = 0; i < txList.size(); ++i )
txStream.appendRaw( txList[i].toBytes() );

RLPStream uncleStream;
uncleStream.appendList( m_uncles.size() );
Expand Down Expand Up @@ -444,7 +441,7 @@ void TestBlock::populateFrom( TestBlock const& _original ) {
m_transactionQueue.clear();
TransactionQueue const& trQueue = _original.transactionQueue();
for ( auto const& txi : trQueue.topTransactions( std::numeric_limits< unsigned >::max() ) )
m_transactionQueue.import( txi.rlp() );
m_transactionQueue.import( txi.toBytes() );

m_uncles = _original.uncles();
m_blockHeader = _original.blockHeader();
Expand Down
4 changes: 2 additions & 2 deletions test/unittests/libdevcrypto/crypto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ BOOST_AUTO_TEST_CASE( keypairs ) {
p.address() == Address( fromHex( "8a40bfaa73256b60764c1bf40675a99083efb075" ) ) );
eth::Transaction t( 1000, 0, 0, h160( fromHex( "944400f4b88ac9589a0f17ed4671da26bddb668b" ) ),
{}, 0, p.secret() );
auto rlp = t.rlp( eth::WithoutSignature );
auto rlp = t.toBytes( eth::WithoutSignature );
auto expectedRlp = "dc80808094944400f4b88ac9589a0f17ed4671da26bddb668b8203e880";
BOOST_CHECK_EQUAL( toHex( rlp ), expectedRlp );
rlp = t.rlp( eth::WithSignature );
rlp = t.toBytes( eth::WithSignature );
auto expectedRlp2 =
"f85f80808094944400f4b88ac9589a0f17ed4671da26bddb668b8203e8801ca0bd2402a510c9c9afddf2a3f63c"
"869573bd257475bea91d6f164638134a3386d6a0609ad9775fd2715e6a359c627e9338478e4adba65dd0dc6ef2"
Expand Down
Loading

0 comments on commit bc9cd39

Please sign in to comment.