Skip to content

Commit

Permalink
pass all unittest
Browse files Browse the repository at this point in the history
  • Loading branch information
ancelmo committed Mar 28, 2019
1 parent 0652f2d commit 4cfae42
Show file tree
Hide file tree
Showing 53 changed files with 3,141 additions and 406 deletions.
9 changes: 6 additions & 3 deletions libblockchain/BlockChainImp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include <libethcore/CommonJS.h>
#include <libethcore/Transaction.h>
#include <libprecompiled/ConsensusPrecompiled.h>
#include <libstorage/MemoryTableFactory.h>
#include <libstorage/Table.h>
#include <tbb/parallel_for.h>
#include <boost/algorithm/string/classification.hpp>
Expand Down Expand Up @@ -108,11 +107,15 @@ void BlockChainImp::setStateFactory(StateFactoryInterface::Ptr _stateFactory)
m_stateFactory = _stateFactory;
}

shared_ptr<MemoryTableFactory> BlockChainImp::getMemoryTableFactory()
shared_ptr<TableFactory> BlockChainImp::getMemoryTableFactory()
{
#if 0
dev::storage::MemoryTableFactory::Ptr memoryTableFactory =
std::make_shared<dev::storage::MemoryTableFactory>();
memoryTableFactory->setStateStorage(m_stateStorage);
#endif

auto memoryTableFactory = m_tableFactoryFactory->newTableFactory(dev::h256(), 0);
return memoryTableFactory;
}

Expand Down Expand Up @@ -425,7 +428,7 @@ bool BlockChainImp::checkAndBuildGenesisBlock(GenesisBlockParam& initParam)
/// modification 2019.3.20: set timestamp to block header
block->setEmptyBlock(initParam.timeStamp);
block->header().appendExtraDataArray(asBytes(initParam.groupMark));
shared_ptr<MemoryTableFactory> mtb = getMemoryTableFactory();
shared_ptr<TableFactory> mtb = getMemoryTableFactory();
Table::Ptr tb = mtb->openTable(SYS_NUMBER_2_HASH, false);
if (tb)
{
Expand Down
7 changes: 6 additions & 1 deletion libblockchain/BlockChainImp.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <libprecompiled/SystemConfigPrecompiled.h>
#include <libstorage/Common.h>
#include <libstorage/Storage.h>
#include <libstorage/Table.h>
#include <libstoragestate/StorageStateFactory.h>
#include <boost/thread/shared_mutex.hpp>
#include <deque>
Expand Down Expand Up @@ -93,7 +94,7 @@ class BlockChainImp : public BlockChainInterface
std::shared_ptr<dev::blockverifier::ExecutiveContext> context) override;
virtual void setStateStorage(dev::storage::Storage::Ptr stateStorage);
virtual void setStateFactory(dev::executive::StateFactoryInterface::Ptr _stateFactory);
virtual std::shared_ptr<dev::storage::MemoryTableFactory> getMemoryTableFactory();
virtual std::shared_ptr<dev::storage::TableFactory> getMemoryTableFactory();
bool checkAndBuildGenesisBlock(GenesisBlockParam& initParam) override;
virtual std::pair<int64_t, int64_t> totalTransactionCount() override;
dev::bytes getCode(dev::Address _address) override;
Expand All @@ -104,6 +105,8 @@ class BlockChainImp : public BlockChainInterface
void getNonces(
std::vector<dev::eth::NonceKeyType>& _nonceVector, int64_t _blockNumber) override;

void setTableFactoryFactory(dev::storage::TableFactoryFactory::Ptr tableFactoryFactory) { m_tableFactoryFactory = tableFactoryFactory; }

private:
std::shared_ptr<dev::eth::Block> getBlock(int64_t _i);
std::shared_ptr<dev::eth::Block> getBlock(dev::h256 const& _blockHash);
Expand Down Expand Up @@ -152,6 +155,8 @@ class BlockChainImp : public BlockChainInterface
/// cache the block number
mutable SharedMutex m_blockNumberMutex;
int64_t m_blockNumber = -1;

dev::storage::TableFactoryFactory::Ptr m_tableFactoryFactory;
};
} // namespace blockchain
} // namespace dev
2 changes: 1 addition & 1 deletion libblockverifier/ExecutiveContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <libethcore/Exceptions.h>
#include <libexecutive/ExecutionResult.h>
#include <libprecompiled/ParallelConfigPrecompiled.h>
#include <libstorage/MemoryTableFactory.h>
#include <libstorage/Table.h>

using namespace dev::executive;
using namespace dev::eth;
Expand Down
8 changes: 4 additions & 4 deletions libblockverifier/ExecutiveContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include <libethcore/Protocol.h>
#include <libethcore/Transaction.h>
#include <libexecutive/StateFace.h>
#include <libstorage/MemoryTableFactory.h>
#include <libstorage/Table.h>
#include <memory>

namespace dev
Expand Down Expand Up @@ -86,12 +86,12 @@ class ExecutiveContext : public std::enable_shared_from_this<ExecutiveContext>

void dbCommit(dev::eth::Block& block);

void setMemoryTableFactory(std::shared_ptr<dev::storage::MemoryTableFactory> memoryTableFactory)
void setMemoryTableFactory(std::shared_ptr<dev::storage::TableFactory> memoryTableFactory)
{
m_memoryTableFactory = memoryTableFactory;
}

std::shared_ptr<dev::storage::MemoryTableFactory> getMemoryTableFactory()
std::shared_ptr<dev::storage::TableFactory> getMemoryTableFactory()
{
return m_memoryTableFactory;
}
Expand All @@ -108,7 +108,7 @@ class ExecutiveContext : public std::enable_shared_from_this<ExecutiveContext>
BlockInfo m_blockInfo;
std::shared_ptr<dev::executive::StateFace> m_stateFace;
std::unordered_map<Address, dev::eth::PrecompiledContract> m_precompiledContract;
std::shared_ptr<dev::storage::MemoryTableFactory> m_memoryTableFactory;
std::shared_ptr<dev::storage::TableFactory> m_memoryTableFactory;
uint64_t m_txGasLimit = 300000000;
};

Expand Down
6 changes: 3 additions & 3 deletions libblockverifier/ExecutiveContextFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,15 @@ using namespace dev::precompiled;
void ExecutiveContextFactory::initExecutiveContext(
BlockInfo blockInfo, h256 stateRoot, ExecutiveContext::Ptr context)
{
#if 0
// DBFactoryPrecompiled
dev::storage::MemoryTableFactory::Ptr memoryTableFactory =
std::make_shared<dev::storage::MemoryTableFactory>();
memoryTableFactory->setStateStorage(m_stateStorage);
memoryTableFactory->setBlockHash(blockInfo.hash);
memoryTableFactory->setBlockNum(blockInfo.number);
#endif
auto memoryTableFactory = m_tableFactoryFactory->newTableFactory(blockInfo.hash, blockInfo.number);

auto tableFactoryPrecompiled = std::make_shared<dev::blockverifier::TableFactoryPrecompiled>();
tableFactoryPrecompiled->setMemoryTableFactory(memoryTableFactory);
Expand Down Expand Up @@ -86,8 +89,6 @@ void ExecutiveContextFactory::setStateFactory(

void ExecutiveContextFactory::setTxGasLimitToContext(ExecutiveContext::Ptr context)
{
(void)context;
#if 0
// get value from db
try
{
Expand Down Expand Up @@ -132,5 +133,4 @@ void ExecutiveContextFactory::setTxGasLimitToContext(ExecutiveContext::Ptr conte
EXECUTIVECONTEXT_LOG(ERROR) << LOG_DESC("[#setTxGasLimitToContext]Failed")
<< LOG_KV("EINFO", boost::diagnostic_information(e));
}
#endif
}
5 changes: 5 additions & 0 deletions libblockverifier/ExecutiveContextFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include <libdevcore/OverlayDB.h>
#include <libexecutive/StateFactoryInterface.h>
#include <libstorage/Storage.h>
#include <libstorage/Table.h>

namespace dev
{
namespace blockverifier
Expand Down Expand Up @@ -57,7 +59,10 @@ class ExecutiveContextFactory : public std::enable_shared_from_this<ExecutiveCon
virtual void setStateFactory(
std::shared_ptr<dev::executive::StateFactoryInterface> stateFactoryInterface);

virtual void setTableFactoryFactory(dev::storage::TableFactoryFactory::Ptr tableFactoryFactory) { m_tableFactoryFactory = tableFactoryFactory; }

private:
dev::storage::TableFactoryFactory::Ptr m_tableFactoryFactory;
dev::storage::Storage::Ptr m_stateStorage;
std::shared_ptr<dev::executive::StateFactoryInterface> m_stateFactoryInterface;
std::unordered_map<Address, dev::eth::PrecompiledContract> m_precompiledContract;
Expand Down
1 change: 1 addition & 0 deletions libconsensus/pbft/PBFTEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <libdevcore/concurrent_queue.h>
#include <libsync/SyncStatus.h>
#include <sstream>
#include <libstorage/Storage.h>

#include <libp2p/P2PMessageFactory.h>
#include <libp2p/P2PSession.h>
Expand Down
2 changes: 1 addition & 1 deletion libexecutive/StateFactoryInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class StateFactoryInterface
StateFactoryInterface() = default;
virtual ~StateFactoryInterface(){};
virtual std::shared_ptr<StateFace> getState(
h256 const& _root, std::shared_ptr<dev::storage::MemoryTableFactory> _factory) = 0;
h256 const& _root, std::shared_ptr<dev::storage::TableFactory> _factory) = 0;
};

} // namespace executive
Expand Down
21 changes: 17 additions & 4 deletions libledger/DBInitializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@
* @date: 2018-10-24
*/
#include "DBInitializer.h"
#include "../libstorage/SQLStorage.h"
#include <libstorage/SQLStorage.h>
#include "LedgerParam.h"
#include <libconfig/GlobalConfigure.h>
#include <libdevcore/Common.h>
#include <libmptstate/MPTStateFactory.h>
#include <libsecurity/EncryptedLevelDB.h>
#include <libstorage/LevelDBStorage.h>
#include <libstoragestate/StorageStateFactory.h>
#include <libstorage/MemoryTableFactoryFactory.h>
#include <libstorage/MemoryTableFactoryFactory2.h>

using namespace dev;
using namespace dev::storage;
Expand Down Expand Up @@ -111,6 +113,11 @@ void DBInitializer::initLevelDBStorage()
std::shared_ptr<dev::db::BasicLevelDB>(pleveldb);
leveldb_storage->setDB(leveldb_handler);
m_storage = leveldb_storage;

auto tableFactoryFactory = std::make_shared<dev::storage::MemoryTableFactoryFactory>();
tableFactoryFactory->setStorage(m_storage);

m_tableFactoryFactory = tableFactoryFactory;
}
catch (std::exception& e)
{
Expand All @@ -136,6 +143,11 @@ void DBInitializer::initSQLStorage()
sqlStorage->setMaxRetry(m_param->mutableStorageParam().maxRetry);

m_storage = sqlStorage;

auto tableFactoryFactory = std::make_shared<dev::storage::MemoryTableFactoryFactory2>();
tableFactoryFactory->setStorage(m_storage);

m_tableFactoryFactory = tableFactoryFactory;
}

/// create ExecutiveContextFactory
Expand All @@ -148,11 +160,12 @@ void DBInitializer::createExecutiveContext()
return;
}
DBInitializer_LOG(DEBUG) << LOG_DESC("createExecutiveContext...");
m_executiveContextFac = std::make_shared<ExecutiveContextFactory>();
m_executiveContextFactory = std::make_shared<ExecutiveContextFactory>();
/// storage
m_executiveContextFac->setStateStorage(m_storage);
m_executiveContextFactory->setStateStorage(m_storage);
// mpt or storage
m_executiveContextFac->setStateFactory(m_stateFactory);
m_executiveContextFactory->setStateFactory(m_stateFactory);
m_executiveContextFactory->setTableFactoryFactory(m_tableFactoryFactory);
DBInitializer_LOG(DEBUG) << LOG_DESC("createExecutiveContext SUCC");
}

Expand Down
8 changes: 6 additions & 2 deletions libledger/DBInitializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <libdevcore/OverlayDB.h>
#include <libexecutive/StateFactoryInterface.h>
#include <libstorage/MemoryTableFactory.h>
#include <libstorage/MemoryTableFactory2.h>
#include <libstorage/Storage.h>
#include <memory>

Expand All @@ -55,11 +56,12 @@ class DBInitializer
createExecutiveContext();
}

dev::storage::TableFactoryFactory::Ptr tableFactoryFactory() { return m_tableFactoryFactory; };
dev::storage::Storage::Ptr storage() const { return m_storage; }
std::shared_ptr<dev::executive::StateFactoryInterface> stateFactory() { return m_stateFactory; }
std::shared_ptr<dev::blockverifier::ExecutiveContextFactory> executiveContextFactory() const
{
return m_executiveContextFac;
return m_executiveContextFactory;
}

virtual void setChannelRPCServer(ChannelRPCServer::Ptr channelRPCServer)
Expand All @@ -86,8 +88,10 @@ class DBInitializer
std::shared_ptr<LedgerParamInterface> m_param;
std::shared_ptr<dev::executive::StateFactoryInterface> m_stateFactory;
dev::storage::Storage::Ptr m_storage = nullptr;
std::shared_ptr<dev::blockverifier::ExecutiveContextFactory> m_executiveContextFac;
std::shared_ptr<dev::blockverifier::ExecutiveContextFactory> m_executiveContextFactory;
std::shared_ptr<ChannelRPCServer> m_channelRPCServer;

dev::storage::TableFactoryFactory::Ptr m_tableFactoryFactory;
};
} // namespace ledger
} // namespace dev
1 change: 1 addition & 0 deletions libledger/Ledger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ bool Ledger::initBlockChain()
}
std::shared_ptr<BlockChainImp> blockChain = std::make_shared<BlockChainImp>();
blockChain->setStateStorage(m_dbInitializer->storage());
//blockChain->setTableFactoryFactory(tableFactoryFactory);
m_blockChain = blockChain;
std::string consensusType = m_param->mutableConsensusParam().consensusType;
std::string storageType = m_param->mutableStorageParam().type;
Expand Down
2 changes: 1 addition & 1 deletion libmptstate/MPTStateFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ using namespace dev::eth;
using namespace dev::executive;

std::shared_ptr<StateFace> MPTStateFactory::getState(
h256 const& _root, std::shared_ptr<dev::storage::MemoryTableFactory>)
h256 const& _root, std::shared_ptr<dev::storage::TableFactory>)
{
if (_root == dev::h256())
{
Expand Down
2 changes: 1 addition & 1 deletion libmptstate/MPTStateFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class MPTStateFactory : public dev::executive::StateFactoryInterface
};
virtual ~MPTStateFactory(){};
virtual std::shared_ptr<dev::executive::StateFace> getState(
h256 const& _root, std::shared_ptr<dev::storage::MemoryTableFactory> _factory) override;
h256 const& _root, std::shared_ptr<dev::storage::TableFactory> _factory) override;

private:
dev::OverlayDB m_db;
Expand Down
Loading

0 comments on commit 4cfae42

Please sign in to comment.