Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Allow missing accounts to create zero-cost transactions #685

Merged
merged 31 commits into from
Jan 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
f1116a0
Ibft transmitted packets are logged by gossiper
Jan 24, 2019
f52c616
touch ups after review
Jan 24, 2019
cbd5a4b
[NC-1970] Added handling in admin_addPeer for when p2p is disabled (#…
Errorific Jan 24, 2019
cbd8f7d
Refactoring for more readable IBFT IT (#614)
CjHare Jan 24, 2019
a0bccde
[NC-1970] admin_addPeer acceptance test (#651)
Errorific Jan 25, 2019
f39db51
add description to automatic benchmarks (#646)
shemnon Jan 25, 2019
eb71f3e
Additional logging details for IBFT (#650)
jframe Jan 25, 2019
ebbde8c
Nc 2026 network option (#645)
NicolasMassart Jan 25, 2019
016e002
Enable CLI config for privacy precompiled contract address (#653)
Puneetha17 Jan 25, 2019
949755d
NC-2120 --discovery-enabled option refactoring (#661)
NicolasMassart Jan 25, 2019
66ce6ee
[NC-1344] Create a simple WorldStateDownloader (#657)
mbaxter Jan 26, 2019
424c91b
Added p2p enabled (#654)
MadelineMurray Jan 26, 2019
a0f8089
Update WorldStateDownloader run() interface to accept header (#677)
mbaxter Jan 28, 2019
a68e22e
Added reference to changelog for CLI changes mapping (#673)
MadelineMurray Jan 28, 2019
ce7e034
Removed available from vX.X notes (#672)
MadelineMurray Jan 28, 2019
8940854
[NC-2137] Add world state and chain download into fast sync workflow …
ajsutton Jan 28, 2019
05a449f
Updated Quickstart docs link (#681)
Errorific Jan 28, 2019
1242930
[NC-2138] Extract out generic parts of Downloader (#659)
ajsutton Jan 28, 2019
9ba5cd0
IBFT available in v1.0 note added (#667)
MadelineMurray Jan 29, 2019
238b4e4
wip
Jan 29, 2019
fa2b1c6
wip
Jan 29, 2019
1c3c240
spotless
Jan 29, 2019
3fa447d
repairs
Jan 29, 2019
ba458d4
post review spotless
Jan 29, 2019
0f4d871
Revert dirty files
Jan 29, 2019
81a8a47
Allow missing accounts to create free transactions
Jan 29, 2019
4ab3b91
cleanup modded files
Jan 29, 2019
faa1758
Merge remote-tracking branch 'upstream/master' into zero_cost_txn
Jan 29, 2019
688ce48
more cleansing
Jan 29, 2019
bb01a84
clean up
Jan 29, 2019
920a115
Merge branch 'master' into zero_cost_txn
rain-on Jan 29, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
*/
public interface Account {

long DEFAULT_NONCE = 0L;
Wei DEFAULT_BALANCE = Wei.ZERO;

/**
* The Keccak-256 hash of the account address.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public interface WorldUpdater extends MutableWorldView {
* and storage.
*/
default MutableAccount createAccount(final Address address) {
return createAccount(address, 0L, Wei.ZERO);
return createAccount(address, Account.DEFAULT_NONCE, Account.DEFAULT_BALANCE);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import tech.pegasys.pantheon.ethereum.core.Account;
import tech.pegasys.pantheon.ethereum.core.Gas;
import tech.pegasys.pantheon.ethereum.core.Transaction;
import tech.pegasys.pantheon.ethereum.core.Wei;
import tech.pegasys.pantheon.ethereum.vm.GasCalculator;

import java.util.OptionalInt;
Expand Down Expand Up @@ -86,32 +87,36 @@ public ValidationResult<TransactionInvalidReason> validate(final Transaction tra
@Override
public ValidationResult<TransactionInvalidReason> validateForSender(
final Transaction transaction, final Account sender, final OptionalLong maximumNonce) {
if (sender == null) {
return ValidationResult.invalid(UPFRONT_COST_EXCEEDS_BALANCE, "Unknown sender account");

Wei balance = Account.DEFAULT_BALANCE;
long nonce = Account.DEFAULT_NONCE;

if (sender != null) {
balance = sender.getBalance();
nonce = sender.getNonce();
}
if (transaction.getUpfrontCost().compareTo(sender.getBalance()) > 0) {

if (transaction.getUpfrontCost().compareTo(balance) > 0) {
return ValidationResult.invalid(
UPFRONT_COST_EXCEEDS_BALANCE,
String.format(
"transaction up-front cost %s exceeds transaction sender account balance %s",
transaction.getUpfrontCost(), sender.getBalance()));
transaction.getUpfrontCost(), balance));
}

if (transaction.getNonce() < sender.getNonce()) {
if (transaction.getNonce() < nonce) {
return ValidationResult.invalid(
NONCE_TOO_LOW,
String.format(
"transaction nonce %s below sender account nonce %s",
transaction.getNonce(), sender.getNonce()));
"transaction nonce %s below sender account nonce %s", transaction.getNonce(), nonce));
}

if (violatesMaximumNonce(transaction, maximumNonce)
&& sender.getNonce() != transaction.getNonce()) {
if (violatesMaximumNonce(transaction, maximumNonce) && nonce != transaction.getNonce()) {
return ValidationResult.invalid(
INCORRECT_NONCE,
String.format(
"transaction nonce %s does not match sender account nonce %s.",
transaction.getNonce(), sender.getNonce()));
transaction.getNonce(), nonce));
}

return ValidationResult.valid();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair;
import tech.pegasys.pantheon.ethereum.core.Account;
import tech.pegasys.pantheon.ethereum.core.Address;
import tech.pegasys.pantheon.ethereum.core.Gas;
import tech.pegasys.pantheon.ethereum.core.Transaction;
import tech.pegasys.pantheon.ethereum.core.TransactionTestFixture;
Expand Down Expand Up @@ -83,16 +84,6 @@ public void shouldRejectTransactionWhenSenderAccountDoesNotExist() {
.isEqualTo(ValidationResult.invalid(UPFRONT_COST_EXCEEDS_BALANCE));
}

@Test
public void shouldRejectTransactionWhenSenderAccountHasInsufficentBalance() {
final MainnetTransactionValidator validator =
new MainnetTransactionValidator(gasCalculator, false, 1);

final Account account = accountWithBalance(basicTransaction.getUpfrontCost().minus(Wei.of(1)));
assertThat(validator.validateForSender(basicTransaction, account, OptionalLong.empty()))
.isEqualTo(ValidationResult.invalid(UPFRONT_COST_EXCEEDS_BALANCE));
}

@Test
public void shouldRejectTransactionWhenTransactionNonceBelowAccountNonce() {
final MainnetTransactionValidator validator =
Expand Down Expand Up @@ -152,6 +143,22 @@ public void shouldRejectTransactionWhenNonceExceedsMaximumAllowedNonce() {
.isEqualTo(ValidationResult.invalid(INCORRECT_NONCE));
}

@Test
public void transactionWithNullSenderCanBeValidIfGasPriceAndValueIsZero() {
final MainnetTransactionValidator validator =
new MainnetTransactionValidator(gasCalculator, false, 1);

final TransactionTestFixture builder = new TransactionTestFixture();
final KeyPair senderKeyPair = KeyPair.generate();
final Address arbitrarySender = Address.fromHexString("1");
builder.gasPrice(Wei.ZERO).nonce(0).sender(arbitrarySender).value(Wei.ZERO);

assertThat(
validator.validateForSender(
builder.createTransaction(senderKeyPair), null, OptionalLong.of(10)))
.isEqualTo(ValidationResult.valid());
}

private Account accountWithNonce(final long nonce) {
return account(basicTransaction.getUpfrontCost(), nonce);
}
Expand Down