Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1199 eth syncing #1742

Merged
merged 6 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions libethereum/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1128,10 +1128,9 @@
}

SyncStatus Client::syncStatus() const {
// TODO implement this when syncing will be needed
SyncStatus s;
s.startBlockNumber = s.currentBlockNumber = s.highestBlockNumber = 0;
return s;
if ( !m_skaleHost )
BOOST_THROW_EXCEPTION( std::runtime_error( "SkaleHost was not initialized" ) );
return m_skaleHost->syncStatus();

Check warning on line 1133 in libethereum/Client.cpp

View check run for this annotation

Codecov / codecov/patch

libethereum/Client.cpp#L1131-L1133

Added lines #L1131 - L1133 were not covered by tests
}

TransactionSkeleton Client::populateTransactionWithDefaults( TransactionSkeleton const& _t ) const {
Expand Down
15 changes: 15 additions & 0 deletions libethereum/SkaleHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,21 @@
return m_consensus->getRandomForBlockId( m_client.number() );
}

dev::eth::SyncStatus SkaleHost::syncStatus() const {
if ( !m_consensus )
BOOST_THROW_EXCEPTION( std::runtime_error( "Consensus was not initialized" ) );
auto syncInfo = m_consensus->getSyncInfo();
dev::eth::SyncStatus syncStatus;

Check warning on line 949 in libethereum/SkaleHost.cpp

View check run for this annotation

Codecov / codecov/patch

libethereum/SkaleHost.cpp#L945-L949

Added lines #L945 - L949 were not covered by tests
// SKALE: catchup downloads blocks with transactions, then the node executes them
// we don't download state changes separately
syncStatus.state = syncInfo.isSyncing ? dev::eth::SyncState::Blocks : dev::eth::SyncState::Idle;
syncStatus.startBlockNumber = syncInfo.startingBlock;
syncStatus.currentBlockNumber = syncInfo.currentBlock;
syncStatus.highestBlockNumber = syncInfo.highestBlock;
syncStatus.majorSyncing = syncInfo.isSyncing;
return syncStatus;

Check warning on line 957 in libethereum/SkaleHost.cpp

View check run for this annotation

Codecov / codecov/patch

libethereum/SkaleHost.cpp#L952-L957

Added lines #L952 - L957 were not covered by tests
}

std::map< std::string, uint64_t > SkaleHost::getConsensusDbUsage() const {
return m_consensus->getConsensusDbUsage();
}
Expand Down
2 changes: 2 additions & 0 deletions libethereum/SkaleHost.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@

namespace dev {
namespace eth {
struct SyncStatus;
class Client;
class TransactionQueue;
class BlockHeader;
Expand Down Expand Up @@ -123,6 +124,7 @@ class SkaleHost {

dev::u256 getGasPrice() const;
dev::u256 getBlockRandom() const;
dev::eth::SyncStatus syncStatus() const;
std::map< std::string, uint64_t > getConsensusDbUsage() const;
std::array< std::string, 4 > getIMABLSPublicKey() const;

Expand Down
27 changes: 18 additions & 9 deletions libweb3jsonrpc/Eth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -892,15 +892,24 @@
}

Json::Value Eth::eth_syncing() {
dev::eth::SyncStatus sync = client()->syncStatus();
if ( sync.state == SyncState::Idle || !sync.majorSyncing )
return Json::Value( false );

Json::Value info( Json::objectValue );
info["startingBlock"] = sync.startBlockNumber;
info["highestBlock"] = sync.highestBlockNumber;
info["currentBlock"] = sync.currentBlockNumber;
return info;
try {
auto client = this->client();
if ( !client )
BOOST_THROW_EXCEPTION( std::runtime_error( "Client was not initialized" ) );

Check warning on line 898 in libweb3jsonrpc/Eth.cpp

View check run for this annotation

Codecov / codecov/patch

libweb3jsonrpc/Eth.cpp#L896-L898

Added lines #L896 - L898 were not covered by tests

// ask consensus whether the node is in catchup mode
dev::eth::SyncStatus sync = client->syncStatus();
if ( !sync.majorSyncing )
return Json::Value( false );

Check warning on line 903 in libweb3jsonrpc/Eth.cpp

View check run for this annotation

Codecov / codecov/patch

libweb3jsonrpc/Eth.cpp#L901-L903

Added lines #L901 - L903 were not covered by tests

Json::Value info( Json::objectValue );
info["startingBlock"] = sync.startBlockNumber;
info["highestBlock"] = sync.highestBlockNumber;
info["currentBlock"] = sync.currentBlockNumber;
return info;
} catch ( const Exception& e ) {
BOOST_THROW_EXCEPTION( jsonrpc::JsonRpcException( e.what() ) );

Check warning on line 911 in libweb3jsonrpc/Eth.cpp

View check run for this annotation

Codecov / codecov/patch

libweb3jsonrpc/Eth.cpp#L905-L911

Added lines #L905 - L911 were not covered by tests
}
}

string Eth::eth_chainId() {
Expand Down
Loading