Skip to content

Commit

Permalink
add support for parallel execute solidity contract
Browse files Browse the repository at this point in the history
  • Loading branch information
JimmyShi22 committed Mar 18, 2019
1 parent 7f83a0d commit 3bbcba3
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 18 deletions.
3 changes: 2 additions & 1 deletion libblockverifier/ExecutiveContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,10 @@ std::shared_ptr<std::vector<std::string>> ExecutiveContext::getTxCriticals(const
ContractABI abi;
string c0, c1;
abi.abiOut(data, c0, c1);
/*
LOG(DEBUG) << LOG_BADGE("PARA") << LOG_DESC("Get normal transaction criticals")
<< LOG_KV("c0", c0) << LOG_KV("c1", c1);

*/
auto res = make_shared<vector<string>>();
res->emplace_back(c0);
res->emplace_back(c1);
Expand Down
2 changes: 1 addition & 1 deletion libexecutive/StateFace.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class StateFace
/// @returns bytes() if no account exists at that address.
/// @warning The reference to the code is only valid until the access to
/// other account. Do not keep it.
virtual bytes const& code(Address const& _addr) const = 0;
virtual bytes const code(Address const& _addr) const = 0;

/// Get the code hash of an account.
/// @returns EmptySHA3 if no account exists at that address or if there is no code associated
Expand Down
2 changes: 1 addition & 1 deletion libmptstate/MPTState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ void MPTState::kill(Address _a)
m_state.kill(_a);
}

bytes const& MPTState::code(Address const& _addr) const
bytes const MPTState::code(Address const& _addr) const
{
return m_state.code(_addr);
}
Expand Down
2 changes: 1 addition & 1 deletion libmptstate/MPTState.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class MPTState : public dev::executive::StateFace
// virtual std::map<h256, std::pair<u256, u256>> storage(Address const& _contract) const
// override;

virtual bytes const& code(Address const& _addr) const override;
virtual bytes const code(Address const& _addr) const override;

virtual h256 codeHash(Address const& _contract) const override;

Expand Down
1 change: 1 addition & 0 deletions libstorage/MemoryTableFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ MemoryTableFactory::MemoryTableFactory() : m_blockHash(h256(0)), m_blockNum(0)
Table::Ptr MemoryTableFactory::openTable(
const std::string& tableName, bool authorityFlag, bool isPara)
{
RecursiveGuard l(x_name2Table);
auto it = m_name2Table.find(tableName);
if (it != m_name2Table.end())
{
Expand Down
7 changes: 5 additions & 2 deletions libstorage/MemoryTableFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ class MemoryTableFactory : public StateDBFactory
MemoryTableFactory();
virtual ~MemoryTableFactory() {}
virtual Table::Ptr openTable(
const std::string& tableName, bool authorityFlag = true, bool isPara = false);
const std::string& tableName, bool authorityFlag = true, bool isPara = true);
virtual Table::Ptr createTable(const std::string& tableName, const std::string& keyField,
const std::string& valueField, bool authorityFlag = true,
Address const& _origin = Address(), bool isPara = false);
Address const& _origin = Address(), bool isPara = true);

virtual Storage::Ptr stateStorage() { return m_stateStorage; }
virtual void setStateStorage(Storage::Ptr stateStorage) { m_stateStorage = stateStorage; }
Expand All @@ -75,6 +75,9 @@ class MemoryTableFactory : public StateDBFactory
h256 m_hash;
std::vector<std::string> m_sysTables;
int createTableCode;

// mutex
mutable RecursiveMutex x_name2Table;
};

} // namespace storage
Expand Down
2 changes: 1 addition & 1 deletion libstoragestate/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ file(GLOB HEADERS "*.h")

add_library(storagestate ${SRC_LIST} ${HEADERS})

target_link_libraries(storagestate PUBLIC storage devcrypto)
target_link_libraries(storagestate PUBLIC storage devcrypto TBB)
11 changes: 3 additions & 8 deletions libstoragestate/StorageState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ void StorageState::setCode(Address const& _address, bytes&& _code)
entry->setField(STORAGE_VALUE, toHex(sha3(_code)));
table->update(ACCOUNT_CODE_HASH, entry, table->newCondition());
}
m_cache[_address] = _code;
}

void StorageState::kill(Address _address)
Expand All @@ -250,11 +249,8 @@ void StorageState::kill(Address _address)
clear();
}

bytes const& StorageState::code(Address const& _address) const
bytes const StorageState::code(Address const& _address) const
{
auto it = m_cache.find(_address);
if (it != m_cache.end())
return it->second;
if (codeHash(_address) == EmptySHA3)
return NullBytes;
auto table = getTable(_address);
Expand All @@ -263,8 +259,7 @@ bytes const& StorageState::code(Address const& _address) const
auto entries = table->select(ACCOUNT_CODE, table->newCondition());
if (entries->size() != 0u)
{
m_cache[_address] = fromHex(entries->get(0)->getField(STORAGE_VALUE));
return m_cache[_address];
return fromHex(entries->get(0)->getField(STORAGE_VALUE));
}
}
return NullBytes;
Expand Down Expand Up @@ -397,7 +392,7 @@ void StorageState::rollback(size_t _savepoint)

void StorageState::clear()
{
m_cache.clear();
// m_cache.clear();
}

bool StorageState::checkAuthority(Address const& _origin, Address const& _contract) const
Expand Down
6 changes: 4 additions & 2 deletions libstoragestate/StorageState.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#pragma once
#include "libexecutive/StateFace.h"
#include <libstorage/MemoryTableFactory.h>
#include <tbb/concurrent_unordered_map.h>
#include <string>

namespace dev
{
Expand All @@ -37,6 +39,7 @@ const char* const ACCOUNT_CODE_HASH = "codeHash";
const char* const ACCOUNT_CODE = "code";
const char* const ACCOUNT_NONCE = "nonce";
const char* const ACCOUNT_ALIVE = "alive";

class StorageState : public dev::executive::StateFace
{
public:
Expand Down Expand Up @@ -113,7 +116,7 @@ class StorageState : public dev::executive::StateFace
/// @returns bytes() if no account exists at that address.
/// @warning The reference to the code is only valid until the access to
/// other account. Do not keep it.
virtual bytes const& code(Address const& _address) const override;
virtual bytes const code(Address const& _address) const override;

/// Get the code hash of an account.
/// @returns EmptySHA3 if no account exists at that address or if there is no code associated
Expand Down Expand Up @@ -172,7 +175,6 @@ class StorageState : public dev::executive::StateFace
}

private:
mutable std::unordered_map<Address, bytes> m_cache;
void createAccount(Address const& _address, u256 const& _nonce, u256 const& _amount = u256(0));
std::shared_ptr<dev::storage::Table> getTable(Address const& _address) const;
/// check authority by caller
Expand Down
2 changes: 1 addition & 1 deletion tools/build_chain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ function generate_group_ini()
;ttl=2
;txpool limit
[tx_pool]
limit=10000
limit=150000
[tx_execute]
enable_parallel=true
EOF
Expand Down

0 comments on commit 3bbcba3

Please sign in to comment.