Search in sources :

Example 1 with RLPOutput

use of org.hyperledger.besu.ethereum.rlp.RLPOutput in project besu by hyperledger.

the class TrieLogLayer method writeTo.

void writeTo(final RLPOutput output) {
    freeze();
    final Set<Address> addresses = new TreeSet<>();
    addresses.addAll(accounts.keySet());
    addresses.addAll(code.keySet());
    addresses.addAll(storage.keySet());
    // container
    output.startList();
    output.writeBytes(blockHash);
    for (final Address address : addresses) {
        // this change
        output.startList();
        output.writeBytes(address);
        final BonsaiValue<StateTrieAccountValue> accountChange = accounts.get(address);
        if (accountChange == null || accountChange.isUnchanged()) {
            output.writeNull();
        } else {
            accountChange.writeRlp(output, (o, sta) -> sta.writeTo(o));
        }
        final BonsaiValue<Bytes> codeChange = code.get(address);
        if (codeChange == null || codeChange.isUnchanged()) {
            output.writeNull();
        } else {
            codeChange.writeRlp(output, RLPOutput::writeBytes);
        }
        final Map<Hash, BonsaiValue<UInt256>> storageChanges = storage.get(address);
        if (storageChanges == null) {
            output.writeNull();
        } else {
            output.startList();
            for (final Map.Entry<Hash, BonsaiValue<UInt256>> storageChangeEntry : storageChanges.entrySet()) {
                output.startList();
                output.writeBytes(storageChangeEntry.getKey());
                storageChangeEntry.getValue().writeInnerRlp(output, RLPOutput::writeUInt256Scalar);
                output.endList();
            }
            output.endList();
        }
        // TODO write trie nodes
        // this change
        output.endList();
    }
    // container
    output.endList();
}
Also used : Address(org.hyperledger.besu.datatypes.Address) StateTrieAccountValue(org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue) Hash(org.hyperledger.besu.datatypes.Hash) Bytes(org.apache.tuweni.bytes.Bytes) TreeSet(java.util.TreeSet) RLPOutput(org.hyperledger.besu.ethereum.rlp.RLPOutput) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 2 with RLPOutput

use of org.hyperledger.besu.ethereum.rlp.RLPOutput in project besu by hyperledger.

the class PingPacketDataTest method handleSourcePortNullHost.

@Test
public void handleSourcePortNullHost() {
    final Endpoint to = new Endpoint("127.0.0.2", 30303, Optional.empty());
    final BytesValueRLPOutput out = new BytesValueRLPOutput();
    final UInt64 enrSeq = UInt64.MAX_VALUE;
    final long time = System.currentTimeMillis();
    out.startList();
    out.writeIntScalar(4);
    ((RLPOutput) out).startList();
    out.writeNull();
    out.writeIntScalar(30303);
    out.writeNull();
    ((RLPOutput) out).endList();
    to.encodeStandalone(out);
    out.writeLongScalar(time);
    out.writeBigIntegerScalar(enrSeq.toBigInteger());
    out.endList();
    final Bytes serialized = out.encoded();
    final PingPacketData deserialized = PingPacketData.readFrom(RLP.input(serialized));
    assertThat(deserialized.getFrom()).isPresent();
    assertThat(deserialized.getFrom().get().getUdpPort()).isEqualTo(30303);
    assertThat(deserialized.getFrom().get().getHost().isEmpty()).isTrue();
    assertThat(deserialized.getFrom().get().getTcpPort().isEmpty()).isTrue();
    assertThat(deserialized.getTo()).isEqualTo(to);
    assertThat(deserialized.getExpiration()).isEqualTo(time);
    assertThat(deserialized.getEnrSeq().isPresent()).isTrue();
    assertThat(deserialized.getEnrSeq().get()).isEqualTo(enrSeq);
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) Endpoint(org.hyperledger.besu.ethereum.p2p.discovery.Endpoint) BytesValueRLPOutput(org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput) RLPOutput(org.hyperledger.besu.ethereum.rlp.RLPOutput) UInt64(org.apache.tuweni.units.bigints.UInt64) BytesValueRLPOutput(org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput) Test(org.junit.Test)

Aggregations

Bytes (org.apache.tuweni.bytes.Bytes)2 RLPOutput (org.hyperledger.besu.ethereum.rlp.RLPOutput)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 TreeSet (java.util.TreeSet)1 UInt64 (org.apache.tuweni.units.bigints.UInt64)1 Address (org.hyperledger.besu.datatypes.Address)1 Hash (org.hyperledger.besu.datatypes.Hash)1 Endpoint (org.hyperledger.besu.ethereum.p2p.discovery.Endpoint)1 BytesValueRLPOutput (org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput)1 StateTrieAccountValue (org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue)1 Test (org.junit.Test)1