Skip to content

Commit

Permalink
SPDX headers, rebase and fix plugin-api hash
Browse files Browse the repository at this point in the history
Signed-off-by: garyschulte <garyschulte@gmail.com>
  • Loading branch information
garyschulte committed Sep 11, 2023
1 parent 9723fda commit 1700245
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2096,7 +2096,7 @@ private void issueOptionWarnings() {

CommandLineUtils.failIfOptionDoesntMeetRequirement(
commandLine,
"--Xsnapsync-synchronizer-flat option can only be used when -Xsnapsync-synchronizer-flat-db-healing-enabled is true",
"--Xsnapsync-synchronizer-flat option can only be used when --Xsnapsync-synchronizer-flat-db-healing-enabled is true",
unstableSynchronizerOptions.isSnapsyncFlatDbHealingEnabled(),
asList(
"--Xsnapsync-synchronizer-flat-account-healed-count-per-request",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,6 @@ public BesuController build() {
final WorldStateStorage worldStateStorage =
storageProvider.createWorldStateStorage(dataStorageConfiguration.getDataStorageFormat());


final BlockchainStorage blockchainStorage =
storageProvider.createBlockchainStorage(protocolSchedule, variablesStorage);

Expand Down Expand Up @@ -1045,7 +1044,8 @@ WorldStateArchive createWorldStateArchive(
switch (dataStorageConfiguration.getDataStorageFormat()) {
case BONSAI:
// just for PoC, explicitly set our bonsai context chain head:
((BonsaiWorldStateKeyValueStorage) worldStateStorage).getFlatDbStrategy()
((BonsaiWorldStateKeyValueStorage) worldStateStorage)
.getFlatDbStrategy()
.updateBlockContext(blockchain.getChainHeadHeader());

return new BonsaiWorldStateProvider(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright Hyperledger Besu Contributors.
*
* 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.bonsai;

import org.hyperledger.besu.plugin.data.BlockHeader;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright Hyperledger Besu Contributors.
*
* 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.bonsai.storage.flat;

import static org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueSegmentIdentifier.ACCOUNT_INFO_STATE;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright Hyperledger Besu Contributors.
*
* 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.bonsai.storage.flat;

public class ArchiveFlatDbReaderStrategyTest {}
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,10 @@ public Optional<NearestKeyValue> getNearestTo(
Comparator.comparing(
(Map.Entry<Bytes, Optional<byte[]>> a) -> a.getKey().commonPrefixLength(key))
.thenComparing((a, b) -> a.getKey().compareTo(b.getKey()));
return this.hashValueStore.computeIfAbsent(segmentIdentifier, s -> new HashMap<>())
.entrySet().stream()
return this.hashValueStore
.computeIfAbsent(segmentIdentifier, s -> new HashMap<>())
.entrySet()
.stream()
.sorted(comparing.reversed())
.findFirst()
.map(z -> new NearestKeyValue(z.getKey(), z.getValue()));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
/*
* Copyright Hyperledger Besu Contributors.
*
* 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.services.kvstore;

import org.apache.tuweni.bytes.Bytes;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hyperledger.besu.services.kvstore.InMemoryKeyValueStorage.SEGMENT_IDENTIFIER;

import org.hyperledger.besu.kvstore.AbstractKeyValueStorageTest;
import org.hyperledger.besu.plugin.services.storage.KeyValueStorageTransaction;
import org.hyperledger.besu.plugin.services.storage.SegmentedKeyValueStorage;
import org.hyperledger.besu.plugin.services.storage.SegmentedKeyValueStorageTransaction;
import org.junit.jupiter.api.Test;

import java.util.stream.IntStream;

import static org.assertj.core.api.Assertions.assertThat;
import static org.hyperledger.besu.services.kvstore.InMemoryKeyValueStorage.SEGMENT_IDENTIFIER;
import org.apache.tuweni.bytes.Bytes;
import org.junit.jupiter.api.Test;

public abstract class AbstractSegmentedKeyValueStorageTest extends AbstractKeyValueStorageTest {
public abstract SegmentedKeyValueStorage createSegmentedStore();
Expand All @@ -21,44 +36,41 @@ public void assertSegmentedIsNearestTo() throws Exception {

// create 10 entries
final SegmentedKeyValueStorageTransaction tx = store.startTransaction();
IntStream.range(0, 10).forEach(i -> {
final byte[] key = bytesFromHexString("000" + i);
final byte[] value = bytesFromHexString("0FFF");
tx.put(SEGMENT_IDENTIFIER, key, value);
// different common prefix, and reversed order of bytes:
final byte[] key2 = bytesFromHexString("010" + (9 - i));
final byte[] value2 = bytesFromHexString("0FFF");
tx.put(SEGMENT_IDENTIFIER, key2, value2);
});
IntStream.range(0, 10)
.forEach(
i -> {
final byte[] key = bytesFromHexString("000" + i);
final byte[] value = bytesFromHexString("0FFF");
tx.put(SEGMENT_IDENTIFIER, key, value);
// different common prefix, and reversed order of bytes:
final byte[] key2 = bytesFromHexString("010" + (9 - i));
final byte[] value2 = bytesFromHexString("0FFF");
tx.put(SEGMENT_IDENTIFIER, key2, value2);
});
tx.commit();

// assert 0009 is closest to 000F
var val =
store.getNearestTo(SEGMENT_IDENTIFIER, Bytes.fromHexString("000F"));
var val = store.getNearestTo(SEGMENT_IDENTIFIER, Bytes.fromHexString("000F"));
assertThat(val).isPresent();
assertThat(val.get().key()).isEqualTo(Bytes.fromHexString("0009"));

// assert 0109 is closest to 010D
var val2 =
store.getNearestTo(SEGMENT_IDENTIFIER, Bytes.fromHexString("010D"));
var val2 = store.getNearestTo(SEGMENT_IDENTIFIER, Bytes.fromHexString("010D"));
assertThat(val2).isPresent();
assertThat(val2.get().key()).isEqualTo(Bytes.fromHexString("0109"));

// assert 0103 is closest to 0103
var val3 =
store.getNearestTo(SEGMENT_IDENTIFIER, Bytes.fromHexString("0103"));
var val3 = store.getNearestTo(SEGMENT_IDENTIFIER, Bytes.fromHexString("0103"));
assertThat(val3).isPresent();
assertThat(val3.get().key()).isEqualTo(Bytes.fromHexString("0103"));

// assert 0003 is closest to 0003
var val4 =
store.getNearestTo(SEGMENT_IDENTIFIER, Bytes.fromHexString("0003"));
var val4 = store.getNearestTo(SEGMENT_IDENTIFIER, Bytes.fromHexString("0003"));
assertThat(val4).isPresent();
assertThat(val4.get().key()).isEqualTo(Bytes.fromHexString("0003"));

// assert 0000 is closest to 0000
var val5 =
store.getNearestTo(SEGMENT_IDENTIFIER, Bytes.fromHexString("0000"));
var val5 = store.getNearestTo(SEGMENT_IDENTIFIER, Bytes.fromHexString("0000"));
assertThat(val5).isPresent();
assertThat(val5.get().key()).isEqualTo(Bytes.fromHexString("0000"));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
/*
* Copyright Hyperledger Besu Contributors.
*
* 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.services.kvstore;

import static org.hyperledger.besu.services.kvstore.InMemoryKeyValueStorage.SEGMENT_IDENTIFIER;

import org.hyperledger.besu.plugin.services.storage.KeyValueStorage;
import org.hyperledger.besu.plugin.services.storage.SegmentedKeyValueStorage;

import static org.hyperledger.besu.services.kvstore.InMemoryKeyValueStorage.SEGMENT_IDENTIFIER;

public class LayeredKeyValueStorageTest extends AbstractSegmentedKeyValueStorageTest {
@Override
protected KeyValueStorage createStore() {
return new SegmentedKeyValueStorageAdapter(SEGMENT_IDENTIFIER,
createSegmentedStore());
return new SegmentedKeyValueStorageAdapter(SEGMENT_IDENTIFIER, createSegmentedStore());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,12 @@

import static org.assertj.core.api.Assertions.assertThat;

import org.apache.tuweni.bytes.Bytes;
import org.hyperledger.besu.kvstore.AbstractKeyValueStorageTest;
import org.hyperledger.besu.plugin.services.storage.KeyValueStorage;
import org.hyperledger.besu.plugin.services.storage.KeyValueStorageTransaction;

import org.junit.jupiter.api.Test;

import java.util.stream.IntStream;

public class LimitedInMemoryKeyValueStorageTest extends AbstractKeyValueStorageTest {

@Override
Expand Down

0 comments on commit 1700245

Please sign in to comment.