|
|
|
@ -180,10 +180,10 @@ public class BonsaiSnapshotWorldStateKeyValueStorage extends BonsaiWorldStateKey |
|
|
|
|
|
|
|
|
|
public static class SnapshotUpdater implements BonsaiWorldStateKeyValueStorage.BonsaiUpdater { |
|
|
|
|
|
|
|
|
|
private final SnappedKeyValueStorage accountStorage; |
|
|
|
|
private final SnappedKeyValueStorage codeStorage; |
|
|
|
|
private final SnappedKeyValueStorage storageStorage; |
|
|
|
|
private final SnappedKeyValueStorage trieBranchStorage; |
|
|
|
|
private final KeyValueStorageTransaction accountStorageTransaction; |
|
|
|
|
private final KeyValueStorageTransaction codeStorageTransaction; |
|
|
|
|
private final KeyValueStorageTransaction storageStorageTransaction; |
|
|
|
|
private final KeyValueStorageTransaction trieBranchStorageTransaction; |
|
|
|
|
private final KeyValueStorageTransaction trieLogStorageTransaction; |
|
|
|
|
|
|
|
|
|
public SnapshotUpdater( |
|
|
|
@ -192,16 +192,16 @@ public class BonsaiSnapshotWorldStateKeyValueStorage extends BonsaiWorldStateKey |
|
|
|
|
final SnappedKeyValueStorage storageStorage, |
|
|
|
|
final SnappedKeyValueStorage trieBranchStorage, |
|
|
|
|
final KeyValueStorage trieLogStorage) { |
|
|
|
|
this.accountStorage = accountStorage; |
|
|
|
|
this.codeStorage = codeStorage; |
|
|
|
|
this.storageStorage = storageStorage; |
|
|
|
|
this.trieBranchStorage = trieBranchStorage; |
|
|
|
|
this.accountStorageTransaction = accountStorage.getSnapshotTransaction(); |
|
|
|
|
this.codeStorageTransaction = codeStorage.getSnapshotTransaction(); |
|
|
|
|
this.storageStorageTransaction = storageStorage.getSnapshotTransaction(); |
|
|
|
|
this.trieBranchStorageTransaction = trieBranchStorage.getSnapshotTransaction(); |
|
|
|
|
this.trieLogStorageTransaction = trieLogStorage.startTransaction(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public BonsaiUpdater removeCode(final Hash accountHash) { |
|
|
|
|
codeStorage.getSnapshotTransaction().remove(accountHash.toArrayUnsafe()); |
|
|
|
|
codeStorageTransaction.remove(accountHash.toArrayUnsafe()); |
|
|
|
|
return this; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -212,13 +212,13 @@ public class BonsaiSnapshotWorldStateKeyValueStorage extends BonsaiWorldStateKey |
|
|
|
|
// Don't save empty values
|
|
|
|
|
return this; |
|
|
|
|
} |
|
|
|
|
codeStorage.getSnapshotTransaction().put(accountHash.toArrayUnsafe(), code.toArrayUnsafe()); |
|
|
|
|
codeStorageTransaction.put(accountHash.toArrayUnsafe(), code.toArrayUnsafe()); |
|
|
|
|
return this; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public BonsaiUpdater removeAccountInfoState(final Hash accountHash) { |
|
|
|
|
accountStorage.getSnapshotTransaction().remove(accountHash.toArrayUnsafe()); |
|
|
|
|
accountStorageTransaction.remove(accountHash.toArrayUnsafe()); |
|
|
|
|
return this; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -228,31 +228,26 @@ public class BonsaiSnapshotWorldStateKeyValueStorage extends BonsaiWorldStateKey |
|
|
|
|
// Don't save empty values
|
|
|
|
|
return this; |
|
|
|
|
} |
|
|
|
|
accountStorage |
|
|
|
|
.getSnapshotTransaction() |
|
|
|
|
.put(accountHash.toArrayUnsafe(), accountValue.toArrayUnsafe()); |
|
|
|
|
accountStorageTransaction.put(accountHash.toArrayUnsafe(), accountValue.toArrayUnsafe()); |
|
|
|
|
return this; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public BonsaiUpdater putStorageValueBySlotHash( |
|
|
|
|
final Hash accountHash, final Hash slotHash, final Bytes storage) { |
|
|
|
|
storageStorage |
|
|
|
|
.getSnapshotTransaction() |
|
|
|
|
.put(Bytes.concatenate(accountHash, slotHash).toArrayUnsafe(), storage.toArrayUnsafe()); |
|
|
|
|
storageStorageTransaction.put( |
|
|
|
|
Bytes.concatenate(accountHash, slotHash).toArrayUnsafe(), storage.toArrayUnsafe()); |
|
|
|
|
return this; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void removeStorageValueBySlotHash(final Hash accountHash, final Hash slotHash) { |
|
|
|
|
storageStorage |
|
|
|
|
.getSnapshotTransaction() |
|
|
|
|
.remove(Bytes.concatenate(accountHash, slotHash).toArrayUnsafe()); |
|
|
|
|
storageStorageTransaction.remove(Bytes.concatenate(accountHash, slotHash).toArrayUnsafe()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public KeyValueStorageTransaction getTrieBranchStorageTransaction() { |
|
|
|
|
return trieBranchStorage.getSnapshotTransaction(); |
|
|
|
|
return trieBranchStorageTransaction; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@ -263,13 +258,9 @@ public class BonsaiSnapshotWorldStateKeyValueStorage extends BonsaiWorldStateKey |
|
|
|
|
@Override |
|
|
|
|
public WorldStateStorage.Updater saveWorldState( |
|
|
|
|
final Bytes blockHash, final Bytes32 nodeHash, final Bytes node) { |
|
|
|
|
trieBranchStorage |
|
|
|
|
.getSnapshotTransaction() |
|
|
|
|
.put(Bytes.EMPTY.toArrayUnsafe(), node.toArrayUnsafe()); |
|
|
|
|
trieBranchStorage.getSnapshotTransaction().put(WORLD_ROOT_HASH_KEY, nodeHash.toArrayUnsafe()); |
|
|
|
|
trieBranchStorage |
|
|
|
|
.getSnapshotTransaction() |
|
|
|
|
.put(WORLD_BLOCK_HASH_KEY, blockHash.toArrayUnsafe()); |
|
|
|
|
trieBranchStorageTransaction.put(Bytes.EMPTY.toArrayUnsafe(), node.toArrayUnsafe()); |
|
|
|
|
trieBranchStorageTransaction.put(WORLD_ROOT_HASH_KEY, nodeHash.toArrayUnsafe()); |
|
|
|
|
trieBranchStorageTransaction.put(WORLD_BLOCK_HASH_KEY, blockHash.toArrayUnsafe()); |
|
|
|
|
return this; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -280,16 +271,14 @@ public class BonsaiSnapshotWorldStateKeyValueStorage extends BonsaiWorldStateKey |
|
|
|
|
// Don't save empty nodes
|
|
|
|
|
return this; |
|
|
|
|
} |
|
|
|
|
trieBranchStorage |
|
|
|
|
.getSnapshotTransaction() |
|
|
|
|
.put(location.toArrayUnsafe(), node.toArrayUnsafe()); |
|
|
|
|
trieBranchStorageTransaction.put(location.toArrayUnsafe(), node.toArrayUnsafe()); |
|
|
|
|
return this; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public WorldStateStorage.Updater removeAccountStateTrieNode( |
|
|
|
|
final Bytes location, final Bytes32 nodeHash) { |
|
|
|
|
trieBranchStorage.getSnapshotTransaction().remove(location.toArrayUnsafe()); |
|
|
|
|
trieBranchStorageTransaction.remove(location.toArrayUnsafe()); |
|
|
|
|
return this; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -300,15 +289,17 @@ public class BonsaiSnapshotWorldStateKeyValueStorage extends BonsaiWorldStateKey |
|
|
|
|
// Don't save empty nodes
|
|
|
|
|
return this; |
|
|
|
|
} |
|
|
|
|
trieBranchStorage |
|
|
|
|
.getSnapshotTransaction() |
|
|
|
|
.put(Bytes.concatenate(accountHash, location).toArrayUnsafe(), node.toArrayUnsafe()); |
|
|
|
|
trieBranchStorageTransaction.put( |
|
|
|
|
Bytes.concatenate(accountHash, location).toArrayUnsafe(), node.toArrayUnsafe()); |
|
|
|
|
return this; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void commit() { |
|
|
|
|
// only commit the trielog layer transaction, leave the snapshot transactions open:
|
|
|
|
|
accountStorageTransaction.commit(); |
|
|
|
|
codeStorageTransaction.commit(); |
|
|
|
|
storageStorageTransaction.commit(); |
|
|
|
|
trieBranchStorageTransaction.commit(); |
|
|
|
|
trieLogStorageTransaction.commit(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|