 |
Ethereum
PoC-8
The C++ Implementation of Ethereum
|
Go to the documentation of this file.
36 #include <libp2p/Common.h>
39 #include <condition_variable>
46 #include <boost/filesystem/path.hpp>
56 class EthereumCapability;
68 std::chrono::system_clock::time_point
since = std::chrono::system_clock::now();
80 std::shared_ptr<GasPricer> _gpForAdoption,
81 boost::filesystem::path
const& _dbPath = boost::filesystem::path(),
82 boost::filesystem::path
const& _snapshotPath = boost::filesystem::path(),
142 std::tuple<ImportRoute, bool, unsigned>
syncQueue(
unsigned _max = 1);
226 std::function<
void(
h256s const&,
h256s const&)> _handler)
232 std::tuple<h256, h256, h256>
getWork()
override;
237 void init(p2p::Host& _extNet, boost::filesystem::path
const& _dbPath,
238 boost::filesystem::path
const& _snapshotPath,
WithExisting _forceAction,
u256 _networkId);
270 void doWork(
bool _doWait);
339 std::shared_ptr<GasPricer>
m_gp;
353 std::weak_ptr<EthereumCapability>
m_host;
368 mutable std::chrono::system_clock::time_point
m_lastTick = std::chrono::system_clock::now();
Block m_preSeal
The present state of the client.
virtual std::string sealer() const
void reopenChain(ChainParams const &_p, WithExisting _we=WithExisting::Trust)
Reloads the blockchain. Just for debug use.
virtual ~Client()
Destructor.
Block preSeal() const override
std::unique_ptr< BlockChainImporterFace > createBlockChainImporter()
A queue of blocks. Sits between network or other I/O and the BlockChain. Sorts them ready for blockch...
BlockQueueStatus status() const
Get some infomration on the current status.
void startedWorking() override
Called when Worker is starting.
boost::shared_mutex SharedMutex
void init(p2p::Host &_extNet, boost::filesystem::path const &_dbPath, boost::filesystem::path const &_snapshotPath, WithExisting _forceAction, u256 _networkId)
bool m_wouldButShouldnot
True if the last time we called rejigSealing wouldSeal() was true but sealer's shouldSeal() was false...
std::tuple< ImportRoute, bool, unsigned > syncQueue(unsigned _max=1)
Freeze worker thread and sync some of the block queue.
SealEngineFace * sealEngine() const override
Get the seal engine.
BlockChain & bc() override
InterfaceStub methods.
unsigned m_syncAmount
Number of blocks to sync in each go.
Encodes a transaction, ready to be exported to or freshly imported from RLP.
BlockHeader m_sealingInfo
The header we're attempting to seal on (derived from m_postSeal).
void rescue(OverlayDB const &_db)
Rescue the database.
void startWorking()
should be called after the constructor of the most derived class finishes.
SharedMutex x_working
Lock on m_working.
std::vector< Transaction > Transactions
Nice name for vector of Transaction.
std::chrono::system_clock::time_point m_lastGarbageCollection
When did we last both doing GC on the watches?
Client(ChainParams const &_params, int _networkID, p2p::Host &_host, std::shared_ptr< GasPricer > _gpForAdoption, boost::filesystem::path const &_dbPath=boost::filesystem::path(), boost::filesystem::path const &_snapshotPath=boost::filesystem::path(), WithExisting _forceAction=WithExisting::Trust, TransactionQueue::Limits const &_l=TransactionQueue::Limits{1024, 1024})
virtual bool isMining() const
SharedMutex x_functionQueue
void setGasPricer(std::shared_ptr< GasPricer > _gp)
Resets the gas pricer to some other object.
std::weak_ptr< EthereumCapability > m_host
void swap(dev::eth::Watch &_a, dev::eth::Watch &_b)
bool wouldSeal() const override
Are we sealing now?
Handler< bytes const & > setOnBlockSealed(std::function< void(bytes const &)> _handler)
Change the function that is called when a new block is sealed.
Address author() const
Get the author address for any transactions we do and rewards we get.
OverlayDB const & stateDB() const
Get the state database.
std::atomic< bool > m_syncTransactionQueue
SyncStatus syncStatus() const override
Get some information on the block syncing.
virtual bool submitSealed(bytes const &_s)
Submit.
BlockQueueStatus blockQueueStatus() const
Get some information on the block queue.
virtual void setSealer(std::string const &)
h256 submitTransaction(TransactionSkeleton const &_t, Secret const &_secret) override
std::atomic< bool > m_syncBlockQueue
void doneWorking() override
Called when Worker is exiting.
SealEngineFace * sealEngine() const
void startSealing() override
Start sealing.
ChainParams const & chainParams() const
Get information on this chain.
Transactions pending() const override
Retrieve pending transactions.
BlockChain m_bc
Maintains block database and owns the seal engine.
void callQueuedFunctions()
Executes the pending functions in m_functionQueue.
bytes option(std::string const &_name) const
u256 networkId() const override
Gets the network id.
std::weak_ptr< WarpCapability > m_warpHost
Base class for all exceptions.
std::atomic< bool > m_needStateReset
Need reset working state to premin on next sync.
SharedMutex x_preSeal
Lock on m_preSeal.
h256 importTransaction(Transaction const &_t) override
Imports the given transaction into the transaction queue.
TransactionQueue::Limits transactionQueueLimits() const
virtual void onNewBlocks(h256s const &_blocks, h256Hash &io_changed)
Called on chain changes.
BlockChain const & bc() const override
ChainParams const & chainParams() const
void resetState()
Clear working state of transactions.
void retryAllUnknown()
Force a retry of all the blocks with unknown parents.
std::tuple< h256, h256, h256 > getWork() override
std::unique_ptr< StateImporterFace > createStateImporter()
void setAuthor(Address const &_us) override
Set the block author address.
std::unordered_set< h256 > h256Hash
std::vector< h256 > h256s
void appendFromNewPending(TransactionReceipt const &_receipt, h256Hash &io_changed, h256 _sha3)
boost::log::sources::severity_channel_logger<> Logger
BlockChain const & blockChain() const
Get the object representing the current canonical blockchain.
std::atomic< bool > m_wouldSeal
True if we /should/ be sealing.
OverlayDB m_stateDB
Acts as the central point for the state database, so multiple States can share it.
dev::eth::Block block(h256 const &_blockHash, PopulationStatistics *o_stats) const
Get the block.
ExecutionResult call(Address const &_secret, u256 _value, Address _dest, bytes const &_data, u256 _gas, u256 _gasPrice, BlockNumber _blockNumber, FudgeFactor _ff=FudgeFactor::Strict) override
Makes the given call. Nothing is recorded into the state.
Main API hub for interfacing with Ethereum.
DownloadMan const * downloadMan() const
#define DEV_WRITE_GUARDED(MUTEX)
u256 gasLimitRemaining() const override
Get the remaining gas limit in this block.
std::vector< byte > bytes
std::atomic< bool > m_remoteWorking
Has the remote worker recently been reset?
std::pair< unsigned, unsigned > items() const
Get information on the items queued.
Logger createLogger(int _severity, std::string const &_channel)
void restartMining()
Update m_preSeal, m_working, m_postSeal blocks from the latest state of the chain.
void resyncStateFromChain()
Called after processing blocks by onChainChanged(_ir)
boost::shared_lock< boost::shared_mutex > ReadGuard
Implements the blockchain database. All data this gives is disk-backed. @threadsafe.
BlockQueue m_bq
Maintains a list of incoming blocks not yet on the blockchain (to be imported).
BlockQueue const & blockQueue() const
Get the block queue.
ImportResult queueBlock(bytes const &_block, bool _isSafe=false)
Queues a block for import.
void syncBlockQueue()
Signal handler for when the block queue needs processing.
void setExtraData(bytes const &_extraData)
Set the extra data that goes into sealed blocks.
Block postSeal() const override
std::shared_ptr< GasPricer > m_gp
The gas pricer.
A queue of Transactions, each stored as RLP. Maintains a transaction queue sorted by nonce diff and g...
void setSealer(std::string const &_id)
Change sealer.
void clearPending()
Clears pending transactions. Just for debug use.
Signal< bytes const & > m_onBlockSealed
Called if we have sealed a new block.
u256 gasBidPrice() const override
Get the gas bid price.
void rewind(unsigned _n)
Rewind to a prior head.
void flushTransactions() override
Blocks until all pending transactions have been processed.
void stopSealing() override
Stop sealing.
bool setSealOption(std::string const &_name, bytes const &_value)
Set option for the sealer.
std::vector< std::string > strings
std::chrono::system_clock::time_point since
void onChainChanged(ImportRoute const &_ir)
virtual strings sealers() const
void appendFromBlock(h256 const &_blockHash, BlockPolarity _polarity, h256Hash &io_changed)
std::queue< std::function< void()> > m_functionQueue
Functions waiting to be executed in the main thread.
std::condition_variable m_signalled
dev::eth::Block postState() const
Get the object representing the current state of Ethereum.
TransactionQueue::Status transactionQueueStatus() const
Get some information on the transaction queue.
Handler< h256 const & > m_tqReplaced
bool remoteActive() const
void startWorking()
Starts worker thread; causes startedWorking() to be called.
void checkWatchGarbage()
Does garbage collection on watches.
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 256, 256, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void > > u256
std::shared_ptr< HandlerAux > add(Callback const &_h)
std::ostream & operator<<(std::ostream &_out, BlockHeader const &_bi)
bool shouldServeWork() const
Is there an active and valid remote worker?
TransactionQueue m_tq
Maintains a list of incoming transactions not yet in a block on the blockchain.
bool isMajorSyncing() const override
Are we syncing the chain?
std::shared_ptr< GasPricer > gasPricer() const
void killChain()
Kills the blockchain. Just for debug use.
void onDeadBlocks(h256s const &_blocks, h256Hash &io_changed)
Called on chain changes.
Block m_working
The state of the client which we're sealing (i.e. it'll have all the rewards added),...
void tick()
Ticks various system-level objects.
bool isSyncing() const override
Are we updating the chain (syncing or importing a new block)?
void onBadBlock(Exception &_ex) const
Description of the result of executing a transaction.
void prepareForTransaction() override
std::string sealer() const
Current sealer in use.
std::chrono::system_clock::time_point m_lastGetWork
Is there an active and valid remote worker?
std::shared_ptr< typename Signal< Args... >::HandlerAux > Handler
bool setOption(std::string const &_name, bytes const &_value)
void noteChanged(h256Hash const &_filters)
void onPostStateChanged()
virtual Block block(h256 const &_h) const =0
std::chrono::system_clock::time_point m_lastTick
When did we last tick()?
std::unique_ptr< StateImporterFace > createStateImporter(OverlayDB &_stateDb)
Super-duper signal mechanism. TODO: replace with somthing a bit heavier weight.
u256 gasLimitRemaining() const
Get the remaining gas limit in this block.
void syncTransactionQueue()
Signal handler for when the block queue needs processing.
void setAuthor(Address const &_id)
void setNetworkId(u256 const &_n) override
Sets the network id.
Block m_postSeal
The state of the client which we're sealing (i.e. it'll have all the rewards added).
ActivityReport activityReport()
Get a report of activity.
void retryUnknown()
Retries all blocks with unknown parents.
strings sealers() const
Type of sealers available for this seal engine.
TransactionSkeleton populateTransactionWithDefaults(TransactionSkeleton const &_t) const override
Populate the uninitialized fields in the supplied transaction with default values.
Active model of a block within the block chain. Keeps track of all transactions, receipts and state f...
SharedMutex x_postSeal
Lock on m_postSeal.
std::unique_ptr< BlockChainImporterFace > createBlockChainImporter(BlockChain &_blockChain)
Signal< h256s const &, h256s const & > m_onChainChanged
Called when blockchain was changed.
Address author() const override
Get the block author address.
void rejigSealing()
Called when wouldSeal(), pendingTransactions() have changed.
void onTransactionQueueReady()
Magically called when m_tq needs syncing. Be nice and don't block.
void doWork() override
Called continuously following sleep for m_idleWaitMs.
void executeInMainThread(std::function< void()> const &_function)
Queues a function to be executed in the main thread (that owns the blockchain, etc).
bytes sealOption(std::string const &_name) const
Review option for the sealer.
Handler< h256s const &, h256s const & > setOnChainChanged(std::function< void(h256s const &, h256s const &)> _handler)
Change the function that is called when blockchain was changed.
void rescue()
Rescue the chain.
void onBlockQueueReady()
Magically called when m_bq needs syncing. Be nice and don't block.