Skip to content

Commit

Permalink
#1755 format
Browse files Browse the repository at this point in the history
  • Loading branch information
olehnikolaiev committed Jan 15, 2025
1 parent adf143b commit 1b1f42f
Show file tree
Hide file tree
Showing 36 changed files with 183 additions and 292 deletions.
2 changes: 1 addition & 1 deletion libdevcore/CommonData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ bytes dev::fromHex( std::string const& _s, WhenError _throw ) {
int h = fromHexChar( _s[i] );
int l = fromHexChar( _s[i + 1] );
if ( h != -1 && l != -1 )
ret.push_back( ( _byte_ ) ( h * 16 + l ) );
ret.push_back( ( _byte_ )( h * 16 + l ) );
else if ( _throw == WhenError::Throw )
BOOST_THROW_EXCEPTION( BadHexCharacter() );
else
Expand Down
4 changes: 2 additions & 2 deletions libdevcore/CommonData.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ template < class T, class _In >
inline T fromBigEndian( _In const& _bytes ) {
T ret = ( T ) 0;
for ( auto i : _bytes )
ret = ( T ) ( ( ret << 8 ) |
( _byte_ ) ( typename std::make_unsigned< decltype( i ) >::type ) i );
ret = ( T )(
( ret << 8 ) | ( _byte_ )( typename std::make_unsigned< decltype( i ) >::type ) i );
return ret;
}

Expand Down
14 changes: 7 additions & 7 deletions libdevcore/RLP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,9 @@ void RLPStream::noteAppended( size_t _itemCount ) {
m_out.resize( os + encodeSize );
memmove( m_out.data() + p + encodeSize, m_out.data() + p, os - p );
if ( s < c_rlpListImmLenCount )
m_out[p] = ( _byte_ ) ( c_rlpListStart + s );
m_out[p] = ( _byte_ )( c_rlpListStart + s );
else if ( c_rlpListIndLenZero + brs <= 0xff ) {
m_out[p] = ( _byte_ ) ( c_rlpListIndLenZero + brs );
m_out[p] = ( _byte_ )( c_rlpListIndLenZero + brs );
_byte_* b = &( m_out[p + brs] );
for ( ; s; s >>= 8 )
*( b-- ) = ( _byte_ ) s;
Expand All @@ -267,7 +267,7 @@ RLPStream& RLPStream::appendList( size_t _items ) {

RLPStream& RLPStream::appendList( bytesConstRef _rlp ) {
if ( _rlp.size() < c_rlpListImmLenCount )
m_out.push_back( ( _byte_ ) ( _rlp.size() + c_rlpListStart ) );
m_out.push_back( ( _byte_ )( _rlp.size() + c_rlpListStart ) );
else
pushCount( _rlp.size(), c_rlpListIndLenZero );
appendRaw( _rlp, 1 );
Expand All @@ -285,7 +285,7 @@ RLPStream& RLPStream::append( bytesConstRef _s, bool _compact ) {
m_out.push_back( *d );
else {
if ( s < c_rlpDataImmLenCount )
m_out.push_back( ( _byte_ ) ( s + c_rlpDataImmLenStart ) );
m_out.push_back( ( _byte_ )( s + c_rlpDataImmLenStart ) );
else
pushCount( s, c_rlpDataIndLenZero );
appendRaw( bytesConstRef( d, s ), 0 );
Expand All @@ -302,13 +302,13 @@ RLPStream& RLPStream::append( bigint _i ) {
else {
unsigned br = bytesRequired( _i );
if ( br < c_rlpDataImmLenCount )
m_out.push_back( ( _byte_ ) ( br + c_rlpDataImmLenStart ) );
m_out.push_back( ( _byte_ )( br + c_rlpDataImmLenStart ) );
else {
auto brbr = bytesRequired( br );
if ( c_rlpDataIndLenZero + brbr > 0xff )
BOOST_THROW_EXCEPTION(
RLPException() << errinfo_comment( "Number too large for RLP" ) );
m_out.push_back( ( _byte_ ) ( c_rlpDataIndLenZero + brbr ) );
m_out.push_back( ( _byte_ )( c_rlpDataIndLenZero + brbr ) );
pushInt( br, brbr );
}
pushInt( _i, br );
Expand All @@ -321,7 +321,7 @@ void RLPStream::pushCount( size_t _count, _byte_ _base ) {
auto br = bytesRequired( _count );
if ( int( br ) + _base > 0xff )
BOOST_THROW_EXCEPTION( RLPException() << errinfo_comment( "Count too large for RLP" ) );
m_out.push_back( ( _byte_ ) ( br + _base ) ); // max 8 bytes.
m_out.push_back( ( _byte_ )( br + _base ) ); // max 8 bytes.
pushInt( _count, br );
}

Expand Down
22 changes: 11 additions & 11 deletions libdevcore/microprofile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -755,10 +755,10 @@ inline uint16_t MicroProfileGetTimerIndex( MicroProfileToken t ) {
return ( t & 0xffff );
}
inline uint32_t MicroProfileGetGroupMask( MicroProfileToken t ) {
return ( uint32_t ) ( ( t >> 16 ) & MICROPROFILE_GROUP_MASK_ALL );
return ( uint32_t )( ( t >> 16 ) & MICROPROFILE_GROUP_MASK_ALL );
}
inline uint32_t MicroProfileGetGroupMaskIndex( MicroProfileToken t ) {
return ( uint32_t ) ( t >> 48 );
return ( uint32_t )( t >> 48 );
}


Expand All @@ -782,7 +782,7 @@ T MicroProfileClamp( T a, T min_, T max_ ) {
}

inline int64_t MicroProfileMsToTick( float fMs, int64_t nTicksPerSecond ) {
return ( int64_t ) ( fMs * 0.001f * nTicksPerSecond );
return ( int64_t )( fMs * 0.001f * nTicksPerSecond );
}

inline float MicroProfileTickToMsMultiplier( int64_t nTicksPerSecond ) {
Expand Down Expand Up @@ -846,7 +846,7 @@ void MicroProfileThreadJoin( MicroProfileThread* pThread ) {
typedef HANDLE MicroProfileThread;
DWORD _stdcall ThreadTrampoline( void* pFunc ) {
MicroProfileThreadFunc F = ( MicroProfileThreadFunc ) pFunc;
return ( uint32_t ) ( uintptr_t ) F( 0 );
return ( uint32_t )( uintptr_t ) F( 0 );
}

void MicroProfileThreadStart( MicroProfileThread* pThread, MicroProfileThreadFunc Func ) {
Expand Down Expand Up @@ -1367,7 +1367,7 @@ MicroProfileToken MicroProfileGetToken(
if ( ret != MICROPROFILE_INVALID_TOKEN )
return ret;
uint16_t nGroupIndex = MicroProfileGetGroup( pGroup, Type );
uint16_t nTimerIndex = ( uint16_t ) ( S.nTotalTimers++ );
uint16_t nTimerIndex = ( uint16_t )( S.nTotalTimers++ );
MP_ASSERT( nTimerIndex < MICROPROFILE_MAX_TIMERS );

uint32_t nBitIndex = nGroupIndex / 32;
Expand Down Expand Up @@ -1452,7 +1452,7 @@ const char* MicroProfileCounterFullName( int nCounter ) {
int nOffset = 0;
while ( nIndex >= 0 && nOffset < ( int ) sizeof( Buffer ) - 2 ) {
uint32_t nLen = S.CounterInfo[nNodes[nIndex]].nNameLen + nOffset; // < sizeof(Buffer)-1
nLen = MicroProfileMin( ( uint32_t ) ( sizeof( Buffer ) - 2 - nOffset ), nLen );
nLen = MicroProfileMin( ( uint32_t )( sizeof( Buffer ) - 2 - nOffset ), nLen );
memcpy( &Buffer[nOffset], S.CounterInfo[nNodes[nIndex]].pName, nLen );

nOffset += S.CounterInfo[nNodes[nIndex]].nNameLen + 1;
Expand Down Expand Up @@ -5663,7 +5663,7 @@ const char* MicroProfileWin32ThreadInfoAddString( const char* pString ) {
if ( 0 == g_ThreadInfo.pStrings[idx] ) {
g_ThreadInfo.pStrings[idx] = &g_ThreadInfo.StringData[g_ThreadInfo.nStringOffset];
memcpy( &g_ThreadInfo.StringData[g_ThreadInfo.nStringOffset], pString, nLen + 1 );
g_ThreadInfo.nStringOffset += ( uint32_t ) ( nLen + 1 );
g_ThreadInfo.nStringOffset += ( uint32_t )( nLen + 1 );
return g_ThreadInfo.pStrings[idx];
}
if ( 0 == strcmp( g_ThreadInfo.pStrings[idx], pString ) ) {
Expand Down Expand Up @@ -5996,7 +5996,7 @@ void* MicroProfileTraceThread( void* unused ) {
gettimeofday( &tv, NULL );

uint64_t nsSinceEpoch =
( ( uint64_t ) ( tv.tv_sec ) * 1000000 + ( uint64_t ) ( tv.tv_usec ) ) * 1000;
( ( uint64_t )( tv.tv_sec ) * 1000000 + ( uint64_t )( tv.tv_usec ) ) * 1000;
uint64_t nTickEpoch = MP_TICK();
uint32_t nLastThread[MICROPROFILE_MAX_CONTEXT_SWITCH_THREADS] = { 0 };
mach_timebase_info_data_t sTimebaseInfo;
Expand Down Expand Up @@ -6306,7 +6306,7 @@ void MicroProfileGpuWaitFence( uint32_t nNode, uint64_t nFence ) {
uint64_t nCompletedFrame = S.pGPU->NodeState[nNode].pFence->GetCompletedValue();
// while(nCompletedFrame < nPending)
// while(0 < nPending - nCompletedFrame)
while ( 0 < ( int64_t ) ( nFence - nCompletedFrame ) ) {
while ( 0 < ( int64_t )( nFence - nCompletedFrame ) ) {
MICROPROFILE_SCOPEI( "Microprofile", "gpu-wait", MP_GREEN4 );
Sleep( 20 ); // todo: use event.
nCompletedFrame = S.pGPU->NodeState[nNode].pFence->GetCompletedValue();
Expand All @@ -6317,7 +6317,7 @@ void MicroProfileGpuFetchResults( uint64_t nFrame ) {
uint64_t nPending = S.pGPU->nPendingFrame;
// while(nPending <= nFrame)
// while(0 <= nFrame - nPending)
while ( 0 <= ( int64_t ) ( nFrame - nPending ) ) {
while ( 0 <= ( int64_t )( nFrame - nPending ) ) {
uint32_t nInternal = nPending % MICROPROFILE_D3D_INTERNAL_DELAY;
uint32_t nNode = S.pGPU->Frames[nInternal].nNode;
MicroProfileGpuWaitFence( nNode, nPending );
Expand Down Expand Up @@ -6610,7 +6610,7 @@ void MicroProfileGpuFetchResults( VkCommandBuffer Buffer, uint64_t nFrame ) {
uint64_t nPending = S.pGPU->nPendingFrame;
// while(nPending <= nFrame)
// while(0 <= nFrame - nPending)
while ( 0 <= ( int64_t ) ( nFrame - nPending ) ) {
while ( 0 <= ( int64_t )( nFrame - nPending ) ) {
uint32_t nInternal = nPending % MICROPROFILE_VULKAN_INTERNAL_DELAY;
uint32_t nNode = S.pGPU->Frames[nInternal].nNode;
MicroProfileGpuWaitFence( nNode, nInternal );
Expand Down
4 changes: 2 additions & 2 deletions libdevcore/microprofile.h
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ typedef uint64_t MicroProfileThreadIdType;
#define MICROPROFILE_COUNTER_LOCAL_ADD( var, count ) \
MicroProfileLocalCounterAdd( &g_mp_local_counter##var, ( count ) )
#define MICROPROFILE_COUNTER_LOCAL_SUB( var, count ) \
MicroProfileLocalCounterAdd( &g_mp_local_counter##var, -( int64_t ) ( count ) )
MicroProfileLocalCounterAdd( &g_mp_local_counter##var, -( int64_t )( count ) )
#define MICROPROFILE_COUNTER_LOCAL_SET( var, count ) \
MicroProfileLocalCounterSet( &g_mp_local_counter##var, count )
#define MICROPROFILE_COUNTER_LOCAL_UPDATE_ADD( var ) \
Expand All @@ -503,7 +503,7 @@ typedef uint64_t MicroProfileThreadIdType;
#define MICROPROFILE_COUNTER_LOCAL_ADD_ATOMIC( var, count ) \
MicroProfileLocalCounterAddAtomic( &g_mp_local_counter##var, ( count ) )
#define MICROPROFILE_COUNTER_LOCAL_SUB_ATOMIC( var, count ) \
MicroProfileLocalCounterAddAtomic( &g_mp_local_counter##var, -( int64_t ) ( count ) )
MicroProfileLocalCounterAddAtomic( &g_mp_local_counter##var, -( int64_t )( count ) )
#define MICROPROFILE_COUNTER_LOCAL_SET_ATOMIC( var, count ) \
MicroProfileLocalCounterSetAtomic( &g_mp_local_counter##var, count )
#define MICROPROFILE_COUNTER_LOCAL_UPDATE_ADD_ATOMIC( var ) \
Expand Down
18 changes: 9 additions & 9 deletions libdevcore/miniz.h
Original file line number Diff line number Diff line change
Expand Up @@ -569,14 +569,14 @@ typedef struct mz_dummy_time_t_tag {
#define MZ_READ_LE16( p ) *( ( const mz_uint16* ) ( p ) )
#define MZ_READ_LE32( p ) *( ( const mz_uint32* ) ( p ) )
#else
#define MZ_READ_LE16( p ) \
( ( mz_uint32 ) ( ( ( const mz_uint8* ) ( p ) )[0] ) | \
( ( mz_uint32 ) ( ( ( const mz_uint8* ) ( p ) )[1] ) << 8U ) )
#define MZ_READ_LE32( p ) \
( ( mz_uint32 ) ( ( ( const mz_uint8* ) ( p ) )[0] ) | \
( ( mz_uint32 ) ( ( ( const mz_uint8* ) ( p ) )[1] ) << 8U ) | \
( ( mz_uint32 ) ( ( ( const mz_uint8* ) ( p ) )[2] ) << 16U ) | \
( ( mz_uint32 ) ( ( ( const mz_uint8* ) ( p ) )[3] ) << 24U ) )
#define MZ_READ_LE16( p ) \
( ( mz_uint32 )( ( ( const mz_uint8* ) ( p ) )[0] ) | \
( ( mz_uint32 )( ( ( const mz_uint8* ) ( p ) )[1] ) << 8U ) )
#define MZ_READ_LE32( p ) \
( ( mz_uint32 )( ( ( const mz_uint8* ) ( p ) )[0] ) | \
( ( mz_uint32 )( ( ( const mz_uint8* ) ( p ) )[1] ) << 8U ) | \
( ( mz_uint32 )( ( ( const mz_uint8* ) ( p ) )[2] ) << 16U ) | \
( ( mz_uint32 )( ( ( const mz_uint8* ) ( p ) )[3] ) << 24U ) )
#endif

#define MZ_READ_LE64( p ) \
Expand Down Expand Up @@ -858,7 +858,7 @@ void* tinfl_decompress_mem_to_heap(
/* tinfl_decompress_mem_to_mem() decompresses a block in memory to another block in memory. */
/* Returns TINFL_DECOMPRESS_MEM_TO_MEM_FAILED on failure, or the number of bytes written on success.
*/
#define TINFL_DECOMPRESS_MEM_TO_MEM_FAILED ( ( size_t ) ( -1 ) )
#define TINFL_DECOMPRESS_MEM_TO_MEM_FAILED ( ( size_t )( -1 ) )
size_t tinfl_decompress_mem_to_mem(
void* pOut_buf, size_t out_buf_len, const void* pSrc_buf, size_t src_buf_len, int flags );

Expand Down
2 changes: 1 addition & 1 deletion libethcore/BlockHeader.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ class BlockHeader {
mutable h256 m_hashWithout; ///< (Memoised) SHA3 hash of the block header without seal.
mutable Mutex m_hashLock; ///< A lock for both m_hash and m_hashWithout.

mutable Logger m_loggerDebug { createLogger( VerbosityDebug, "blockhdr" ) };
mutable Logger m_loggerDebug{ createLogger( VerbosityDebug, "blockhdr" ) };

Counter< BlockHeader > c;

Expand Down
22 changes: 13 additions & 9 deletions libethereum/Block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,8 @@ pair< TransactionReceipts, bool > Block::sync(

if ( req > got ) {
// too old
LOG( m_loggerDebug ) << t.sha3() << " Dropping old transaction (nonce too low)";
LOG( m_loggerDebug )
<< t.sha3() << " Dropping old transaction (nonce too low)";
_tq.drop( t.sha3() );
} else if ( got > req + _tq.waiting( t.sender() ) ) {
// too new
Expand All @@ -402,9 +403,10 @@ pair< TransactionReceipts, bool > Block::sync(
<< "got: " << got << " required: " << m_currentBlock.gasLimit();
_tq.drop( t.sha3() );
} else {
LOG( m_loggerDebug ) << t.sha3()
<< " Temporarily no gas left in current block (txs gas > "
"block's gas limit)";
LOG( m_loggerDebug )
<< t.sha3()
<< " Temporarily no gas left in current block (txs gas > "
"block's gas limit)";
//_tq.drop(t.sha3());
// Temporarily no gas left in current block.
// OPTIMISE: could note this and then we don't evaluate until a block that
Expand Down Expand Up @@ -485,8 +487,9 @@ tuple< TransactionReceipts, unsigned > Block::syncEveryone(

// TODO Move this checking logic into some single place - not in execute, of course
if ( !tr.isInvalid() && !tr.hasExternalGas() && tr.gasPrice() < _gasPrice ) {
LOG( m_loggerDebug ) << "Transaction " << tr.sha3() << " WouldNotBeInBlock: gasPrice "
<< tr.gasPrice() << " < " << _gasPrice;
LOG( m_loggerDebug )
<< "Transaction " << tr.sha3() << " WouldNotBeInBlock: gasPrice "
<< tr.gasPrice() << " < " << _gasPrice;

if ( SkipInvalidTransactionsPatch::isEnabledInWorkingBlock() ) {
// Add to the user-originated transactions that we've executed.
Expand Down Expand Up @@ -597,7 +600,7 @@ u256 Block::enactOn( VerifiedBlockRef const& _block, BlockChain const& _bc ) {
enactment = t.elapsed();
if ( populateVerify + populateGrand + syncReset + enactment > 0.5 )
LOG( m_loggerDebug ) << "popVer/popGrand/syncReset/enactment = " << populateVerify << " / "
<< populateGrand << " / " << syncReset << " / " << enactment;
<< populateGrand << " / " << syncReset << " / " << enactment;
#endif
return ret;
}
Expand Down Expand Up @@ -1130,7 +1133,8 @@ void Block::cleanup() {
MICROPROFILE_SCOPEI( "Block", "cleanup", MP_BEIGE );

// Commit the new trie to disk.
// LOG(m_loggerDebug) << "Committing to disk: stateRoot " << m_currentBlock.stateRoot() << " = "
// LOG(m_loggerDebug) << "Committing to disk: stateRoot " << m_currentBlock.stateRoot() << "
// = "
// << rootHash() << " = " << toHex(asBytes(db().lookup(globalRoot())));

// try
Expand All @@ -1152,7 +1156,7 @@ void Block::cleanup() {
sealEngine()->populateFromParent( m_currentBlock, m_previousBlock );

LOG( m_loggerDebug ) << "finalising enactment. current -> previous, hash is "
<< m_previousBlock.hash();
<< m_previousBlock.hash();

resetCurrent();
}
28 changes: 7 additions & 21 deletions libethereum/Block.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,29 +287,19 @@ class Block {
* // unlock
* @endcode
*/
bool sealBlock( bytes const& _header ) {
return sealBlock( &_header );
}
bool sealBlock( bytes const& _header ) { return sealBlock( &_header ); }
bool sealBlock( bytesConstRef _header );

/// @returns true if sealed - in this case you can no longer append transactions.
bool isSealed() const {
return !m_currentBytes.empty();
}
bool isSealed() const { return !m_currentBytes.empty(); }

/// Get the complete current block, including valid nonce.
/// Only valid when isSealed() is true.
bytes const& blockData() const {
return m_currentBytes;
}
bytes const& blockData() const { return m_currentBytes; }

/// Get the header information on the present block.
BlockHeader const& info() const {
return m_currentBlock;
}
BlockHeader const& previousInfo() const {
return m_previousBlock;
}
BlockHeader const& info() const { return m_currentBlock; }
BlockHeader const& previousInfo() const { return m_previousBlock; }

void startReadState();

Expand All @@ -328,9 +318,7 @@ class Block {
std::vector< BlockHeader > const& _uncleBlockHeaders, u256 const& _blockReward );

/// @returns gas used by transactions thus far executed.
u256 gasUsed() const {
return m_receipts.size() ? m_receipts.back().cumulativeGasUsed() : 0;
}
u256 gasUsed() const { return m_receipts.size() ? m_receipts.back().cumulativeGasUsed() : 0; }

/// Performs irregular modifications right after initialization, e.g. to implement a hard fork.
void performIrregularModifications();
Expand Down Expand Up @@ -367,9 +355,7 @@ class Block {
;

public:
static uint64_t howMany() {
return Counter< Block >::howMany();
}
static uint64_t howMany() { return Counter< Block >::howMany(); }
};


Expand Down
11 changes: 5 additions & 6 deletions libethereum/BlockChain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ void BlockChain::open( fs::path const& _path, bool _applyPatches, WithExisting _
m_lastBlockNumber = number( m_lastBlockHash );

LOG( m_loggerDebug ) << "Opened blockchain DB. Latest: " << currentHash() << ' '
<< m_lastBlockNumber;
<< m_lastBlockNumber;

// dump_blocks_and_extras_db( *this, 0 );

Expand Down Expand Up @@ -508,7 +508,8 @@ ImportRoute BlockChain::import( VerifiedBlockRef const& _block, State& _state, b
// Work out its number as the parent's number + 1
if ( !isKnown( _block.info.parentHash(), false ) ) // doesn't have to be current.
{
LOG( m_loggerDebug ) << _block.info.hash() << " : Unknown parent " << _block.info.parentHash();
LOG( m_loggerDebug ) << _block.info.hash() << " : Unknown parent "
<< _block.info.parentHash();
// We don't know the parent (yet) - discard for now. It'll get resent to us if we find out
// about its ancestry later on.
BOOST_THROW_EXCEPTION( UnknownParent() << errinfo_hash256( _block.info.parentHash() ) );
Expand Down Expand Up @@ -908,7 +909,7 @@ void BlockChain::recomputeExistingOccupiedSpaceForBlockRotation() try {
}

LOG( m_loggerDebug ) << "pieceUsageBytes from DB = " << pieceUsageBytes
<< " computed = " << blocksBatchSize + extrasBatchSize;
<< " computed = " << blocksBatchSize + extrasBatchSize;

if ( pieceUsageBytes == 0 ) {
pieceUsageBytes = blocksBatchSize + extrasBatchSize;
Expand Down Expand Up @@ -1425,9 +1426,7 @@ void BlockChain::doLevelDbCompaction() const {
}

void BlockChain::checkConsistency() {
DEV_WRITE_GUARDED( x_details ) {
m_details.clear();
}
DEV_WRITE_GUARDED( x_details ) { m_details.clear(); }

m_blocksDB->forEach( [this]( db::Slice const& _key, db::Slice const& /* _value */ ) {
if ( _key.size() == 32 ) {
Expand Down
Loading

0 comments on commit 1b1f42f

Please sign in to comment.