Skip to content
This repository has been archived by the owner on Oct 28, 2021. It is now read-only.

Commit

Permalink
Replace bool by enum.
Browse files Browse the repository at this point in the history
  • Loading branch information
chriseth committed Oct 28, 2016
1 parent 37e8043 commit 9ece109
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
10 changes: 5 additions & 5 deletions libethereum/Block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -625,9 +625,9 @@ u256 Block::enact(VerifiedBlockRef const& _block, BlockChain const& _bc)
applyRewards(rewarded, _bc.chainParams().blockReward);

// Commit all cached state changes to the state trie.
bool killEmptyAccounts = m_currentBlock.number() >= _bc.chainParams().u256Param("EIP158ForkBlock");
bool removeEmptyAccounts = m_currentBlock.number() >= _bc.chainParams().u256Param("EIP158ForkBlock");
DEV_TIMED_ABOVE("commit", 500)
m_state.commit(killEmptyAccounts);
m_state.commit(removeEmptyAccounts ? State::CommitBehaviour::RemoveEmptyAccounts : State::CommitBehaviour::KeepEmptyAccounts);

// Hash the state trie and check against the state_root hash in m_currentBlock.
if (m_currentBlock.stateRoot() != m_previousBlock.stateRoot() && m_currentBlock.stateRoot() != rootHash())
Expand Down Expand Up @@ -689,7 +689,7 @@ void Block::performIrregularModifications()
Addresses allDAOs = childDaos();
for (Address const& dao: allDAOs)
m_state.transferBalance(dao, recipient, m_state.balance(dao));
m_state.commit(false);
m_state.commit(State::CommitBehaviour::KeepEmptyAccounts);
}
}

Expand Down Expand Up @@ -769,9 +769,9 @@ void Block::commitToSeal(BlockChain const& _bc, bytes const& _extraData)
applyRewards(uncleBlockHeaders, _bc.chainParams().blockReward);

// Commit any and all changes to the trie that are in the cache, then update the state root accordingly.
bool killEmptyAccounts = m_currentBlock.number() >= _bc.chainParams().u256Param("EIP158ForkBlock");
bool removeEmptyAccounts = m_currentBlock.number() >= _bc.chainParams().u256Param("EIP158ForkBlock");
DEV_TIMED_ABOVE("commit", 500)
m_state.commit(killEmptyAccounts);
m_state.commit(removeEmptyAccounts ? State::CommitBehaviour::RemoveEmptyAccounts : State::CommitBehaviour::KeepEmptyAccounts);

clog(StateDetail) << "Post-reward stateRoot:" << m_state.rootHash();
clog(StateDetail) << m_state;
Expand Down
14 changes: 7 additions & 7 deletions libethereum/State.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ OverlayDB State::openDB(std::string const& _basePath, h256 const& _genesisHash,
void State::populateFrom(AccountMap const& _map)
{
eth::commit(_map, m_state);
commit(false);
commit(State::CommitBehaviour::KeepEmptyAccounts);
}

u256 const& State::requireAccountStartNonce() const
Expand All @@ -135,7 +135,7 @@ void State::noteAccountStartNonce(u256 const& _actual)
BOOST_THROW_EXCEPTION(IncorrectAccountStartNonceInState());
}

void State::killEmptyAccounts()
void State::removeEmptyAccounts()
{
for (auto& i: m_cache)
if (i.second.isDirty() && i.second.isEmpty())
Expand Down Expand Up @@ -269,10 +269,10 @@ void State::clearCacheIfTooLarge() const
}
}

void State::commit(bool _killEmptyAccounts)
void State::commit(CommitBehaviour _commitBehaviour)
{
if (_killEmptyAccounts)
killEmptyAccounts();
if (_commitBehaviour == CommitBehaviour::RemoveEmptyAccounts)
removeEmptyAccounts();
m_touched += dev::eth::commit(m_cache, m_state);
m_cache.clear();
}
Expand Down Expand Up @@ -556,8 +556,8 @@ std::pair<ExecutionResult, TransactionReceipt> State::execute(EnvInfo const& _en
m_cache.clear();
else
{
bool killEmptyAccounts = _envInfo.number() >= _sealEngine->chainParams().u256Param("EIP158ForkBlock");
commit(killEmptyAccounts);
bool removeEmptyAccounts = _envInfo.number() >= _sealEngine->chainParams().u256Param("EIP158ForkBlock");
commit(removeEmptyAccounts ? State::CommitBehaviour::RemoveEmptyAccounts : State::CommitBehaviour::KeepEmptyAccounts);

#if ETH_PARANOIA && !ETH_FATDB
ctrace << "Executed; now" << rootHash();
Expand Down
12 changes: 9 additions & 3 deletions libethereum/State.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ class State
friend class BlockChain;

public:
enum class CommitBehaviour
{
KeepEmptyAccounts,
RemoveEmptyAccounts
};

/// Default constructor; creates with a blank database prepopulated with the genesis block.
explicit State(u256 const& _accountStartNonce): State(_accountStartNonce, OverlayDB(), BaseState::Empty) {}

Expand Down Expand Up @@ -243,8 +249,8 @@ class State
StateDiff diff(State const& _c, bool _quick = false) const;

/// Commit all changes waiting in the address cache to the DB.
/// @param _killEmptyAccounts if true, will remove all "touched" empty accounts from the state.
void commit(bool _killEmptyAccounts);
/// @param _commitBehaviour whether or not to remove empty accounts during commit.
void commit(CommitBehaviour _commitBehaviour);

/// Resets any uncommitted changes to the cache.
void setRoot(h256 const& _root);
Expand All @@ -256,7 +262,7 @@ class State

private:
/// Turns all "touched" empty accounts into non-alive accounts.
void killEmptyAccounts();
void removeEmptyAccounts();

/// @returns the account at the given address or a null pointer if it does not exist.
/// The pointer is valid until the next access to the state or account.
Expand Down
2 changes: 1 addition & 1 deletion test/TestUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void ClientBaseFixture::enumerateClients(std::function<void(Json::Value const&,
enumerateBlockchains([&callback](Json::Value const& _json, BlockChain const& _bc, State _state) -> void
{
cerr << "void ClientBaseFixture::enumerateClients. FixedClient now accepts block not sate!" << endl;
_state.commit(false); //unused variable. remove this line
_state.commit(State::CommitBehaviour::KeepEmptyAccounts); //unused variable. remove this line
eth::Block b(Block::Null);
b.noteChain(_bc);
FixedClient client(_bc, b);
Expand Down

0 comments on commit 9ece109

Please sign in to comment.