-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
x WIP clang-format WIP x
- Loading branch information
Showing
15 changed files
with
456 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright (c) 2018 The unit-e core developers | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#include <esperanza/proposer_logic.h> | ||
|
||
#include <esperanza/stakevalidation.h> | ||
#include <esperanza/walletextension.h> | ||
#include <miner.h> | ||
#include <util.h> | ||
#include <validation.h> | ||
#include <wallet/wallet.h> | ||
|
||
namespace esperanza { | ||
|
||
CWallet *wallet; | ||
// | ||
// std::shared_ptr<const CBlock> ProposeBlock( | ||
// const CChainParams &chainParams, CWallet *wallet, | ||
// const BlockProposalRequest &blockProposalRequest) { | ||
// | ||
// CScript coinbaseScript; | ||
// BlockAssembler blockAssembler(chainParams); | ||
// std::unique_ptr<CBlockTemplate> blockTemplate = | ||
// blockAssembler.CreateNewBlock(coinbaseScript, /* fMineWitnessTx */ | ||
// true); | ||
// | ||
// if (!blockTemplate) { | ||
// // did not get block template | ||
// return nullptr; | ||
// } | ||
// | ||
// WalletExtension &walletExt = wallet->GetWalletExtension(); | ||
// | ||
// // CreateCoinStake() | ||
// // SignBlock() | ||
// | ||
// const CBlock &block = blockTemplate->block; | ||
// auto sharedBlock = std::make_shared<const CBlock>(block); | ||
// | ||
// if (!CheckBlock(block)) { | ||
// // failed PoS validation | ||
// return nullptr; | ||
// } | ||
// | ||
// if (!::ProcessNewBlock(chainParams, sharedBlock, | ||
// /* fForceProcessing */ true, | ||
// /* fNewBlock out */ nullptr)) { | ||
// return nullptr; | ||
// } | ||
// return sharedBlock; | ||
//} | ||
// | ||
// class BlockAssemblerAdapter { | ||
// | ||
// private: | ||
// BlockAssembler blockAssembler; | ||
// | ||
// | ||
// | ||
//}; | ||
|
||
} // namespace esperanza |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright (c) 2018 The unit-e core developers | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#include <chainparams.h> | ||
|
||
#include <stdint.h> | ||
|
||
#ifndef UNIT_E_ESPERANZA_PROPOSER_LOGIC_H | ||
#define UNIT_E_ESPERANZA_PROPOSER_LOGIC_H | ||
|
||
class CWallet; | ||
|
||
namespace esperanza { | ||
// | ||
// struct BlockProposalRequest { | ||
// int64_t blockTime; | ||
// uint64_t blockHeight; | ||
// uint64_t targetDifficulty; | ||
//}; | ||
// | ||
////! \brief tries to propose a block using the given block proposal request | ||
// std::shared_ptr<const CBlock> ProposeBlock(const CChainParams &, CWallet *, | ||
// const BlockProposalRequest &); | ||
|
||
} // namespace esperanza | ||
|
||
#endif // UNIT_E_PROPOSER_LOGIC_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright (c) 2018 The unit-e core developers | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#include "blockproposer.h" | ||
|
||
namespace proposer { | ||
|
||
class BlockProposerImpl : public BlockProposer { | ||
|
||
private: | ||
ChainInterface &m_chain; | ||
|
||
public: | ||
BlockProposerImpl(ChainInterface &chain) : m_chain(chain) {} | ||
|
||
std::shared_ptr<const CBlock> ProposeBlock( | ||
const ProposeBlockParameters ¶meters) { | ||
//m_chain.ProcessNewBlock(nullptr); | ||
return nullptr; | ||
}; | ||
}; | ||
|
||
std::shared_ptr<BlockProposer> BlockProposer::MakeBlockProposer( | ||
ChainInterface &chain) { | ||
return std::shared_ptr<BlockProposer>(new BlockProposerImpl(chain)); | ||
} | ||
|
||
} // namespace proposer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright (c) 2018 The unit-e core developers | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#ifndef UNIT_E_PROPOSER_BLOCKPROPOSER_H | ||
#define UNIT_E_PROPOSER_BLOCKPROPOSER_H | ||
|
||
#include <proposer/chaininterface.h> | ||
|
||
#include <stdint.h> | ||
|
||
#include <memory> | ||
|
||
class CBlock; | ||
class CWallet; | ||
|
||
namespace proposer { | ||
|
||
//! \brief a component for proposing new blocks. | ||
//! | ||
//! The block proposer will build and propose a block, given a wallet | ||
//! that has enough stake. | ||
//! | ||
//! The BlockProposer is different from the Proposer in proposer.cpp. | ||
//! That one is managing concurrency (number of staking threads), | ||
//! availability of wallets, balance, etc. The BlockProposer is used | ||
//! to actually propose a block once we know that we have the means to | ||
//! do so. | ||
//! | ||
//! This class is an interface. | ||
class BlockProposer { | ||
|
||
public: | ||
struct ProposeBlockParameters { | ||
//! \brief the height to propose the block for. | ||
//! | ||
//! The height of a block is encoded inside the coinbase transaction. | ||
//! This is defined in BIP34 (Block v2, Height in Coinbase). | ||
//! This also helps ensuring that the coinbase transaction has a | ||
//! unique hash, hence prevent BIP30 (Duplicate transactions) from | ||
//! applying. | ||
//! | ||
//! Block height is up to 2^31 which is enough to support one block | ||
//! every second for 68 years. This is because block height used to | ||
//! be signed and the signbit is now overloaded in some places to | ||
//! signal a coinstake transaction in various serializations of | ||
//! coins / UTXOs. | ||
uint32_t blockHeight; | ||
|
||
//! \brief the block time to propose the block with. | ||
int64_t blockTime; | ||
|
||
//! \brief the wallet to draw funds for staking from. | ||
//! | ||
//! The stake to propose with is drawn from the given wallet. The | ||
//! amount of stake will increase the chances of proposing since | ||
//! a certain difficulty threshold has to be met in order to do so. | ||
CWallet *wallet; | ||
}; | ||
|
||
virtual std::shared_ptr<const CBlock> ProposeBlock( | ||
const ProposeBlockParameters &) = 0; | ||
|
||
virtual ~BlockProposer() = default; | ||
|
||
//! \brief Factory method for creating a BlockProposer | ||
static std::shared_ptr<BlockProposer> MakeBlockProposer(ChainInterface &); | ||
}; | ||
|
||
} // namespace proposer | ||
|
||
#endif // UNIT_E_PROPOSER_BLOCKPROPOSER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright (c) 2018 The unit-e core developers | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#include <proposer/chaininterface.h> | ||
|
||
#include <chainparams.h> | ||
#include <timedata.h> | ||
#include <util.h> | ||
#include <validation.h> | ||
|
||
namespace proposer { | ||
|
||
class ChainAdapter final : public ChainInterface { | ||
|
||
CCriticalSection& GetLock() const override { | ||
return cs_main; | ||
} | ||
|
||
uint32_t GetHeight() const override { | ||
const int height = chainActive.Height(); | ||
if (height < 0) { | ||
throw std::runtime_error("no active chain yet"); | ||
} | ||
return static_cast<uint32_t>(height); | ||
}; | ||
|
||
std::unique_ptr<const CBlockHeader> GetTip() const override { | ||
const CBlockIndex *tip = chainActive.Tip(); | ||
if (tip == nullptr) { | ||
throw std::runtime_error("no active chain yet"); | ||
} | ||
return MakeUnique<const CBlockHeader>(tip->GetBlockHeader()); | ||
}; | ||
|
||
bool ProcessNewBlock(std::shared_ptr<const CBlock> pblock) override { | ||
bool newBlock; | ||
return ::ProcessNewBlock(::Params(), pblock, true, &newBlock); | ||
}; | ||
|
||
::SyncStatus GetInitialBlockDownloadStatus() const override { | ||
return ::GetInitialBlockDownloadStatus(); | ||
} | ||
}; | ||
|
||
std::shared_ptr<ChainInterface> ChainInterface::MakeChainInterface() { | ||
return std::shared_ptr<ChainInterface>(new ChainAdapter()); | ||
} | ||
|
||
} // namespace proposer |
Oops, something went wrong.