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