Skip to content

Commit

Permalink
Decrease message severity for non-existing account (#7833)
Browse files Browse the repository at this point in the history
  • Loading branch information
benaadams authored Nov 28, 2024
1 parent 5516619 commit 65cd94d
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -435,14 +435,7 @@ private void ApplyMinerReward(Block block, BlockReward reward, IReleaseSpec spec
{
if (_logger.IsTrace) _logger.Trace($" {(BigInteger)reward.Value / (BigInteger)Unit.Ether:N3}{Unit.EthSymbol} for account at {reward.Address}");

if (!_stateProvider.AccountExists(reward.Address))
{
_stateProvider.CreateAccount(reward.Address, reward.Value);
}
else
{
_stateProvider.AddToBalance(reward.Address, reward.Value, spec);
}
_stateProvider.AddToBalanceAndCreateIfNotExists(reward.Address, reward.Value, spec);
}

// TODO: block processor pipeline
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,7 @@ public void ProcessWithdrawals(Block block, IReleaseSpec spec)
if (_logger.IsTrace) _logger.Trace($" {withdrawal.AmountInGwei} GWei to account {withdrawal.Address}");

// Consensus clients are using Gwei for withdrawals amount. We need to convert it to Wei before applying state changes https://github.com/ethereum/execution-apis/pull/354
if (_stateProvider.AccountExists(withdrawal.Address))
{
_stateProvider.AddToBalance(withdrawal.Address, withdrawal.AmountInWei, spec);
}
else
{
_stateProvider.CreateAccount(withdrawal.Address, withdrawal.AmountInWei);
}
_stateProvider.AddToBalanceAndCreateIfNotExists(withdrawal.Address, withdrawal.AmountInWei, spec);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Nethermind/Nethermind.Evm/StateOverridesExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ private static void UpdateBalance(
}
else if (balance < newBalance)
{
stateProvider.AddToBalance(address, newBalance - balance, spec);
stateProvider.AddToBalanceAndCreateIfNotExists(address, newBalance - balance, spec);
}
}
}
Expand Down
29 changes: 3 additions & 26 deletions src/Nethermind/Nethermind.Evm/VirtualMachine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -574,16 +574,7 @@ private CallResult ExecutePrecompile(EvmState state, IReleaseSpec spec)
long baseGasCost = precompile.BaseGasCost(spec);
long blobGasCost = precompile.DataGasCost(callData, spec);

bool wasCreated = false;
if (!_state.AccountExists(state.Env.ExecutingAccount))
{
wasCreated = true;
_state.CreateAccount(state.Env.ExecutingAccount, transferValue);
}
else
{
_state.AddToBalance(state.Env.ExecutingAccount, transferValue, spec);
}
bool wasCreated = _state.AddToBalanceAndCreateIfNotExists(state.Env.ExecutingAccount, transferValue, spec);

// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-161.md
// An additional issue was found in Parity,
Expand Down Expand Up @@ -639,14 +630,7 @@ private CallResult ExecuteCall<TTracingInstructions>(EvmState vmState, ReadOnlyM
ref readonly ExecutionEnvironment env = ref vmState.Env;
if (!vmState.IsContinuation)
{
if (!_state.AccountExists(env.ExecutingAccount))
{
_state.CreateAccount(env.ExecutingAccount, env.TransferValue);
}
else
{
_state.AddToBalance(env.ExecutingAccount, env.TransferValue, spec);
}
_state.AddToBalanceAndCreateIfNotExists(env.ExecutingAccount, env.TransferValue, spec);

if (vmState.ExecutionType.IsAnyCreate() && spec.ClearEmptyAccountWhenTouched)
{
Expand Down Expand Up @@ -2247,14 +2231,7 @@ private EvmExceptionType InstructionCall<TTracingInstructions, TTracingRefunds>(

EvmExceptionType FastCall(IReleaseSpec spec, out object returnData, in UInt256 transferValue, Address target)
{
if (!_state.AccountExists(target))
{
_state.CreateAccount(target, transferValue);
}
else
{
_state.AddToBalance(target, transferValue, spec);
}
_state.AddToBalanceAndCreateIfNotExists(target, transferValue, spec);
Metrics.IncrementEmptyCalls();

returnData = CallResult.BoxedEmpty;
Expand Down
2 changes: 1 addition & 1 deletion src/Nethermind/Nethermind.State/IWorldState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public interface IWorldState : IJournal<Snapshot>, IReadOnlyStateProvider

void AddToBalance(Address address, in UInt256 balanceChange, IReleaseSpec spec);

void AddToBalanceAndCreateIfNotExists(Address address, in UInt256 balanceChange, IReleaseSpec spec);
bool AddToBalanceAndCreateIfNotExists(Address address, in UInt256 balanceChange, IReleaseSpec spec);

void SubtractFromBalance(Address address, in UInt256 balanceChange, IReleaseSpec spec);

Expand Down
6 changes: 4 additions & 2 deletions src/Nethermind/Nethermind.State/StateProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ Account GetThroughCacheCheckExists()
Account result = GetThroughCache(address);
if (result is null)
{
if (_logger.IsError) _logger.Error("Updating balance of a non-existing account");
if (_logger.IsDebug) _logger.Debug("Updating balance of a non-existing account");
throw new InvalidOperationException("Updating balance of a non-existing account");
}

Expand Down Expand Up @@ -383,15 +383,17 @@ public void CreateAccountIfNotExists(Address address, in UInt256 balance, in UIn
}
}

public void AddToBalanceAndCreateIfNotExists(Address address, in UInt256 balance, IReleaseSpec spec)
public bool AddToBalanceAndCreateIfNotExists(Address address, in UInt256 balance, IReleaseSpec spec)
{
if (AccountExists(address))
{
AddToBalance(address, balance, spec);
return false;
}
else
{
CreateAccount(address, balance);
return true;
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Nethermind/Nethermind.State/WorldState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ public void AddToBalance(Address address, in UInt256 balanceChange, IReleaseSpec
{
_stateProvider.AddToBalance(address, balanceChange, spec);
}
public void AddToBalanceAndCreateIfNotExists(Address address, in UInt256 balanceChange, IReleaseSpec spec)
public bool AddToBalanceAndCreateIfNotExists(Address address, in UInt256 balanceChange, IReleaseSpec spec)
{
_stateProvider.AddToBalanceAndCreateIfNotExists(address, balanceChange, spec);
return _stateProvider.AddToBalanceAndCreateIfNotExists(address, balanceChange, spec);
}
public void SubtractFromBalance(Address address, in UInt256 balanceChange, IReleaseSpec spec)
{
Expand Down

0 comments on commit 65cd94d

Please sign in to comment.