mirror of https://github.com/hyperledger/besu
Signed-off-by: Matilda-Clerke <matilda.clerke@consensys.net>pull/7781/head
commit
bedf3d0d5d
@ -0,0 +1,24 @@ |
||||
{ |
||||
"request": { |
||||
"id": 3, |
||||
"jsonrpc": "2.0", |
||||
"method": "eth_call", |
||||
"params": [ |
||||
{ |
||||
"to": "0x6295ee1b4f6dd65047762f924ecd367c17eabf8f", |
||||
"from": "a94f5374fce5edbc8e2a8697c15331677e6ebf0b", |
||||
"data": "0x12a7b914" |
||||
}, |
||||
"latest", |
||||
{ |
||||
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b": {} |
||||
} |
||||
] |
||||
}, |
||||
"response": { |
||||
"jsonrpc": "2.0", |
||||
"id": 3, |
||||
"result": "0x0000000000000000000000000000000000000000000000000000000000000001" |
||||
}, |
||||
"statusCode": 200 |
||||
} |
@ -0,0 +1,32 @@ |
||||
{ |
||||
"request": { |
||||
"id": 3, |
||||
"jsonrpc": "2.0", |
||||
"method": "eth_call", |
||||
"params": [ |
||||
{ |
||||
"to": "0x6295ee1b4f6dd65047762f924ecd367c17eabf8f", |
||||
"from": "a94f5374fce5edbc8e2a8697c15331677e6ebf0b", |
||||
"data": "0x12a7b914" |
||||
}, |
||||
"latest", |
||||
{ |
||||
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b": { |
||||
"balance": "0xde0b6b3a7640000", |
||||
"nonce": 88 |
||||
}, |
||||
"0xb9741079a300Cb3B8f324CdDB847c0d1d273a05E": { |
||||
"stateDiff": { |
||||
"0x1cf7945003fc5b59d2f6736f0704557aa805c4f2844084ccd1173b8d56946962": "0x000000000000000000000000000000000000000000000000000000110ed03bf7" |
||||
} |
||||
} |
||||
} |
||||
] |
||||
}, |
||||
"response": { |
||||
"jsonrpc": "2.0", |
||||
"id": 3, |
||||
"result": "0x0000000000000000000000000000000000000000000000000000000000000001" |
||||
}, |
||||
"statusCode": 200 |
||||
} |
@ -0,0 +1,34 @@ |
||||
{ |
||||
"request": { |
||||
"id": 3, |
||||
"jsonrpc": "2.0", |
||||
"method": "eth_call", |
||||
"params": [ |
||||
{ |
||||
"to": "0x6295ee1b4f6dd65047762f924ecd367c17eabf8f", |
||||
"from": "a94f5374fce5edbc8e2a8697c15331677e6ebf0b", |
||||
"value": "0x000002" |
||||
}, |
||||
"latest", |
||||
{ |
||||
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b": { |
||||
"balance": "0x000001" |
||||
}, |
||||
"0xb9741079a300Cb3B8f324CdDB847c0d1d273a05E": { |
||||
"stateDiff": { |
||||
"0x1cf7945003fc5b59d2f6736f0704557aa805c4f2844084ccd1173b8d56946962": "0x000000000000000000000000000000000000000000000000000000110ed03bf7" |
||||
} |
||||
} |
||||
} |
||||
] |
||||
}, |
||||
"response": { |
||||
"jsonrpc": "2.0", |
||||
"id": 3, |
||||
"error" : { |
||||
"code" : -32004, |
||||
"message" : "Upfront cost exceeds account balance" |
||||
} |
||||
}, |
||||
"statusCode": 200 |
||||
} |
@ -1,38 +0,0 @@ |
||||
/* |
||||
* Copyright ConsenSys AG. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
package org.hyperledger.besu.ethereum; |
||||
|
||||
import org.hyperledger.besu.ethereum.chain.Blockchain; |
||||
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; |
||||
import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; |
||||
|
||||
/** The ConsensusContextFactory interface defines a method for creating a consensus context. */ |
||||
@FunctionalInterface |
||||
public interface ConsensusContextFactory { |
||||
|
||||
/** |
||||
* Creates a consensus context with the given blockchain, world state archive, and protocol |
||||
* schedule. |
||||
* |
||||
* @param blockchain the blockchain |
||||
* @param worldStateArchive the world state archive |
||||
* @param protocolSchedule the protocol schedule |
||||
* @return the created consensus context |
||||
*/ |
||||
ConsensusContext create( |
||||
Blockchain blockchain, |
||||
WorldStateArchive worldStateArchive, |
||||
ProtocolSchedule protocolSchedule); |
||||
} |
@ -0,0 +1,147 @@ |
||||
/* |
||||
* Copyright contributors to Besu. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
package org.hyperledger.besu.ethereum.util; |
||||
|
||||
import org.hyperledger.besu.datatypes.Wei; |
||||
|
||||
import java.util.Map; |
||||
import java.util.Objects; |
||||
import java.util.Optional; |
||||
|
||||
import com.fasterxml.jackson.annotation.JsonAnySetter; |
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
|
||||
// similar to AccountDiff
|
||||
// BUT
|
||||
// there are more fields that need to be added
|
||||
// stateDiff
|
||||
// movePrecompileToAddress
|
||||
@JsonIgnoreProperties(ignoreUnknown = true) |
||||
@JsonDeserialize(builder = AccountOverride.Builder.class) |
||||
public class AccountOverride { |
||||
private static final Logger LOG = LoggerFactory.getLogger(AccountOverride.class); |
||||
|
||||
private final Optional<Wei> balance; |
||||
private final Optional<Long> nonce; |
||||
private final Optional<String> code; |
||||
private final Optional<Map<String, String>> stateDiff; |
||||
|
||||
private AccountOverride( |
||||
final Optional<Wei> balance, |
||||
final Optional<Long> nonce, |
||||
final Optional<String> code, |
||||
final Optional<Map<String, String>> stateDiff) { |
||||
this.balance = balance; |
||||
this.nonce = nonce; |
||||
this.code = code; |
||||
this.stateDiff = stateDiff; |
||||
} |
||||
|
||||
public Optional<Wei> getBalance() { |
||||
return balance; |
||||
} |
||||
|
||||
public Optional<Long> getNonce() { |
||||
return nonce; |
||||
} |
||||
|
||||
public Optional<String> getCode() { |
||||
return code; |
||||
} |
||||
|
||||
public Optional<Map<String, String>> getStateDiff() { |
||||
return stateDiff; |
||||
} |
||||
|
||||
public static class Builder { |
||||
private Optional<Wei> balance = Optional.empty(); |
||||
private Optional<Long> nonce = Optional.empty(); |
||||
private Optional<String> code = Optional.empty(); |
||||
private Optional<Map<String, String>> stateDiff = Optional.empty(); |
||||
|
||||
/** Default constructor. */ |
||||
public Builder() {} |
||||
|
||||
public Builder withBalance(final Wei balance) { |
||||
this.balance = Optional.ofNullable(balance); |
||||
return this; |
||||
} |
||||
|
||||
public Builder withNonce(final Long nonce) { |
||||
this.nonce = Optional.ofNullable(nonce); |
||||
return this; |
||||
} |
||||
|
||||
public Builder withCode(final String code) { |
||||
this.code = Optional.ofNullable(code); |
||||
return this; |
||||
} |
||||
|
||||
public Builder withStateDiff(final Map<String, String> stateDiff) { |
||||
this.stateDiff = Optional.ofNullable(stateDiff); |
||||
return this; |
||||
} |
||||
|
||||
public AccountOverride build() { |
||||
return new AccountOverride(balance, nonce, code, stateDiff); |
||||
} |
||||
} |
||||
|
||||
@JsonAnySetter |
||||
public void withUnknownProperties(final String key, final Object value) { |
||||
LOG.debug( |
||||
"unknown property - {} with value - {} and type - {} caught during serialization", |
||||
key, |
||||
value, |
||||
value != null ? value.getClass() : "NULL"); |
||||
} |
||||
|
||||
@Override |
||||
public boolean equals(final Object o) { |
||||
if (this == o) { |
||||
return true; |
||||
} |
||||
if (o == null || getClass() != o.getClass()) { |
||||
return false; |
||||
} |
||||
final AccountOverride accountOverride = (AccountOverride) o; |
||||
return balance.equals(accountOverride.balance) |
||||
&& nonce.equals(accountOverride.nonce) |
||||
&& code.equals(accountOverride.code) |
||||
&& stateDiff.equals(accountOverride.stateDiff); |
||||
} |
||||
|
||||
@Override |
||||
public int hashCode() { |
||||
return Objects.hash(balance, nonce, code, stateDiff); |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return "AccountOverride{" |
||||
+ "balance=" |
||||
+ balance |
||||
+ ", nonce=" |
||||
+ nonce |
||||
+ ", code=" |
||||
+ code |
||||
+ ", stateDiff=" |
||||
+ stateDiff |
||||
+ '}'; |
||||
} |
||||
} |
@ -0,0 +1,27 @@ |
||||
/* |
||||
* Copyright contributors to Besu. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
package org.hyperledger.besu.ethereum.util; |
||||
|
||||
import org.hyperledger.besu.datatypes.Address; |
||||
|
||||
import java.util.HashMap; |
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true) |
||||
public class AccountOverrideMap extends HashMap<Address, AccountOverride> { |
||||
|
||||
public AccountOverrideMap() {} |
||||
} |
@ -0,0 +1,24 @@ |
||||
/* |
||||
* Copyright contributors to Besu. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
package org.hyperledger.besu.ethereum.core; |
||||
|
||||
import org.hyperledger.besu.ethereum.ConsensusContext; |
||||
|
||||
public class ConsensusContextFixture implements ConsensusContext { |
||||
@Override |
||||
public <C extends ConsensusContext> C as(final Class<C> klass) { |
||||
return klass.cast(this); |
||||
} |
||||
} |
@ -0,0 +1,188 @@ |
||||
/* |
||||
* Copyright contributors to Besu. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
package org.hyperledger.besu.ethereum.util; |
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat; |
||||
import static org.junit.jupiter.api.Assertions.assertFalse; |
||||
import static org.junit.jupiter.api.Assertions.assertTrue; |
||||
|
||||
import org.hyperledger.besu.datatypes.Address; |
||||
import org.hyperledger.besu.datatypes.Wei; |
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest; |
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; |
||||
|
||||
import java.util.Optional; |
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper; |
||||
import org.junit.jupiter.api.Test; |
||||
|
||||
public class AccountOverrideParameterTest { |
||||
|
||||
private static final String ADDRESS_HEX1 = "0xd9c9cd5f6779558b6e0ed4e6acf6b1947e7fa1f3"; |
||||
private static final String ADDRESS_HEX2 = "0xd5E23607D5d73ff2293152f464C3caB005f87696"; |
||||
private static final String STORAGE_KEY = |
||||
"0x1cf7945003fc5b59d2f6736f0704557aa805c4f2844084ccd1173b8d56946962"; |
||||
private static final String STORAGE_VALUE = |
||||
"0x000000000000000000000000000000000000000000000000000000110ed03bf7"; |
||||
private static final String CODE_STRING = |
||||
"0xdbf4257000000000000000000000000000000000000000000000000000000000"; |
||||
|
||||
@Test |
||||
public void jsonDeserializesCorrectly() throws Exception { |
||||
final String json = |
||||
"{\"jsonrpc\":\"2.0\",\"method\":\"eth_call\",\"params\":[{" |
||||
+ "\"from\":\"0x0\", \"to\": \"0x0\"}, " |
||||
+ "\"latest\"," |
||||
+ "{\"" |
||||
+ ADDRESS_HEX1 |
||||
+ "\":" |
||||
+ "{" |
||||
+ "\"balance\": \"0x01\"," |
||||
+ "\"nonce\": 88" |
||||
+ "}}],\"id\":1}"; |
||||
|
||||
final JsonRpcRequestContext request = new JsonRpcRequestContext(readJsonAsJsonRpcRequest(json)); |
||||
final AccountOverrideMap accountOverrideParam = |
||||
request.getRequiredParameter(2, AccountOverrideMap.class); |
||||
|
||||
final AccountOverride accountOverride = |
||||
accountOverrideParam.get(Address.fromHexString(ADDRESS_HEX1)); |
||||
|
||||
assertThat(accountOverride.getNonce()).isEqualTo(Optional.of(88L)); |
||||
assertThat(accountOverride.getBalance()).isEqualTo(Optional.of(Wei.of(1))); |
||||
assertFalse(accountOverride.getStateDiff().isPresent()); |
||||
} |
||||
|
||||
@Test |
||||
public void jsonWithCodeDeserializesCorrectly() throws Exception { |
||||
final String json = |
||||
"{\"jsonrpc\":\"2.0\",\"method\":\"eth_call\",\"params\":[{" |
||||
+ "\"from\":\"0x0\", \"to\": \"0x0\"}, " |
||||
+ "\"latest\"," |
||||
+ "{\"" |
||||
+ ADDRESS_HEX1 |
||||
+ "\":" |
||||
+ "{" |
||||
+ "\"balance\": \"0x01\"," |
||||
+ "\"code\": \"" |
||||
+ CODE_STRING |
||||
+ "\"" |
||||
+ "}}],\"id\":1}"; |
||||
|
||||
final JsonRpcRequestContext request = new JsonRpcRequestContext(readJsonAsJsonRpcRequest(json)); |
||||
final AccountOverrideMap accountOverrideParam = |
||||
request.getRequiredParameter(2, AccountOverrideMap.class); |
||||
|
||||
final AccountOverride accountOverride = |
||||
accountOverrideParam.get(Address.fromHexString(ADDRESS_HEX1)); |
||||
|
||||
assertFalse(accountOverride.getNonce().isPresent()); |
||||
assertThat(accountOverride.getBalance()).isEqualTo(Optional.of(Wei.of(1))); |
||||
assertThat(accountOverride.getCode()).isEqualTo(Optional.of(CODE_STRING)); |
||||
assertFalse(accountOverride.getStateDiff().isPresent()); |
||||
} |
||||
|
||||
@Test |
||||
public void jsonWithStorageOverridesDeserializesCorrectly() throws Exception { |
||||
final String json = |
||||
"{\"jsonrpc\":\"2.0\",\"method\":\"eth_call\",\"params\":[{" |
||||
+ "\"from\":\"0x0\", \"to\": \"0x0\"}, " |
||||
+ "\"latest\"," |
||||
+ "{\"" |
||||
+ ADDRESS_HEX1 |
||||
+ "\":" |
||||
+ "{" |
||||
+ "\"balance\": \"0x01\"," |
||||
+ "\"nonce\": 88," |
||||
+ "\"stateDiff\": {" |
||||
+ "\"" |
||||
+ STORAGE_KEY |
||||
+ "\": \"" |
||||
+ STORAGE_VALUE |
||||
+ "\"" |
||||
+ "}}}],\"id\":1}"; |
||||
|
||||
final JsonRpcRequestContext request = new JsonRpcRequestContext(readJsonAsJsonRpcRequest(json)); |
||||
|
||||
final AccountOverrideMap accountOverrideParam = |
||||
request.getRequiredParameter(2, AccountOverrideMap.class); |
||||
assertThat(accountOverrideParam.size()).isEqualTo(1); |
||||
|
||||
final AccountOverride accountOverride = |
||||
accountOverrideParam.get(Address.fromHexString(ADDRESS_HEX1)); |
||||
assertThat(accountOverride.getNonce()).isEqualTo(Optional.of(88L)); |
||||
|
||||
assertTrue(accountOverride.getStateDiff().isPresent()); |
||||
assertThat(accountOverride.getStateDiff().get().get(STORAGE_KEY)).isEqualTo(STORAGE_VALUE); |
||||
} |
||||
|
||||
@Test |
||||
public void jsonWithMultipleAccountOverridesDeserializesCorrectly() throws Exception { |
||||
final String json = |
||||
"{\"jsonrpc\":\"2.0\",\"method\":\"eth_call\",\"params\":[{" |
||||
+ "\"from\":\"0x0\", \"to\": \"0x0\"}, " |
||||
+ "\"latest\"," |
||||
+ "{\"" |
||||
+ ADDRESS_HEX1 |
||||
+ "\":" |
||||
+ "{" |
||||
+ "\"balance\": \"0x01\"," |
||||
+ "\"nonce\": 88," |
||||
+ "\"stateDiff\": {" |
||||
+ "\"" |
||||
+ STORAGE_KEY |
||||
+ "\": \"" |
||||
+ STORAGE_VALUE |
||||
+ "\"" |
||||
+ "}}," |
||||
+ "\"" |
||||
+ ADDRESS_HEX2 |
||||
+ "\":" |
||||
+ "{" |
||||
+ "\"balance\": \"0xFF\"," |
||||
+ "\"nonce\": 99," |
||||
+ "\"stateDiff\": {" |
||||
+ "\"" |
||||
+ STORAGE_KEY |
||||
+ "\": \"" |
||||
+ STORAGE_VALUE |
||||
+ "\"" |
||||
+ "}}}],\"id\":1}"; |
||||
|
||||
final JsonRpcRequestContext request = new JsonRpcRequestContext(readJsonAsJsonRpcRequest(json)); |
||||
|
||||
final AccountOverrideMap accountOverrideParam = |
||||
request.getRequiredParameter(2, AccountOverrideMap.class); |
||||
assertThat(accountOverrideParam.size()).isEqualTo(2); |
||||
|
||||
final AccountOverride accountOverride1 = |
||||
accountOverrideParam.get(Address.fromHexString(ADDRESS_HEX1)); |
||||
assertThat(accountOverride1.getNonce()).isEqualTo(Optional.of(88L)); |
||||
assertThat(accountOverride1.getBalance()).isEqualTo(Optional.of(Wei.fromHexString("0x01"))); |
||||
assertTrue(accountOverride1.getStateDiff().isPresent()); |
||||
assertThat(accountOverride1.getStateDiff().get().get(STORAGE_KEY)).isEqualTo(STORAGE_VALUE); |
||||
|
||||
final AccountOverride accountOverride2 = |
||||
accountOverrideParam.get(Address.fromHexString(ADDRESS_HEX2)); |
||||
assertThat(accountOverride2.getNonce()).isEqualTo(Optional.of(99L)); |
||||
assertThat(accountOverride2.getBalance()).isEqualTo(Optional.of(Wei.fromHexString("0xFF"))); |
||||
assertTrue(accountOverride2.getStateDiff().isPresent()); |
||||
assertThat(accountOverride2.getStateDiff().get().get(STORAGE_KEY)).isEqualTo(STORAGE_VALUE); |
||||
} |
||||
|
||||
private JsonRpcRequest readJsonAsJsonRpcRequest(final String json) throws java.io.IOException { |
||||
return new ObjectMapper().readValue(json, JsonRpcRequest.class); |
||||
} |
||||
} |
@ -0,0 +1,36 @@ |
||||
/* |
||||
* Copyright contributors to Besu. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
package org.hyperledger.besu.plugin.services.metrics; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* Record of summary data the is kept outside the metric system. Useful when existing libraries |
||||
* calculate the summary data on their own, and we want to export that summary via the configured |
||||
* metric system. A notable example are RocksDB statistics. |
||||
* |
||||
* @param count the number of observations |
||||
* @param sum the sum of all the observations |
||||
* @param quantiles a list of quantiles with values |
||||
*/ |
||||
public record ExternalSummary(long count, double sum, List<Quantile> quantiles) { |
||||
/** |
||||
* Represent a single quantile and its value |
||||
* |
||||
* @param quantile the quantile |
||||
* @param value the value |
||||
*/ |
||||
public record Quantile(double quantile, double value) {} |
||||
} |
Loading…
Reference in new issue