-
Notifications
You must be signed in to change notification settings - Fork 849
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
eth_call now supports GoQuorum private transactions (#1934)
eth_call now supports GoQuorum private transactions Signed-off-by: Sally MacFarlane <[email protected]>
- Loading branch information
Showing
7 changed files
with
174 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
...m/core/src/main/java/org/hyperledger/besu/ethereum/goquorum/GoQuorumPrivateStateUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* 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.goquorum; | ||
|
||
import static org.apache.logging.log4j.LogManager.getLogger; | ||
|
||
import org.hyperledger.besu.ethereum.core.BlockHeader; | ||
import org.hyperledger.besu.ethereum.core.GoQuorumPrivacyParameters; | ||
import org.hyperledger.besu.ethereum.core.Hash; | ||
import org.hyperledger.besu.ethereum.core.MutableWorldState; | ||
import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; | ||
|
||
import java.util.Optional; | ||
|
||
import org.apache.logging.log4j.Logger; | ||
|
||
public class GoQuorumPrivateStateUtil { | ||
private static final Logger LOG = getLogger(); | ||
|
||
public static MutableWorldState getPrivateWorldState( | ||
final Optional<GoQuorumPrivacyParameters> goQuorumPrivacyParameters, | ||
final BlockHeader header) { | ||
final GoQuorumPrivateStorage goQuorumPrivateStorage = | ||
goQuorumPrivacyParameters.orElseThrow().privateStorage(); | ||
final WorldStateArchive goQuorumWorldStateArchive = | ||
goQuorumPrivacyParameters.orElseThrow().worldStateArchive(); | ||
return getPrivateWorldState(goQuorumPrivateStorage, goQuorumWorldStateArchive, header); | ||
} | ||
|
||
public static MutableWorldState getPrivateWorldState( | ||
final GoQuorumPrivateStorage goQuorumPrivateStorage, | ||
final WorldStateArchive goQuorumWorldStateArchive, | ||
final BlockHeader header) { | ||
final Hash worldStateRootHash = header.getStateRoot(); | ||
final Hash publicBlockHash = header.getHash(); | ||
final Hash privateStateRootHash = | ||
goQuorumPrivateStorage | ||
.getPrivateStateRootHash(worldStateRootHash) | ||
.orElse(Hash.EMPTY_TRIE_HASH); | ||
|
||
final Optional<MutableWorldState> maybePrivateWorldState = | ||
goQuorumWorldStateArchive.getMutable(privateStateRootHash, publicBlockHash); | ||
if (maybePrivateWorldState.isEmpty()) { | ||
LOG.debug( | ||
"Private world state not available for public world state root hash {}, public block hash {}", | ||
worldStateRootHash, | ||
publicBlockHash); | ||
|
||
/* | ||
This should never happen because privateStateRootResolver will either return a matching | ||
private world state root hash, or the hash for an empty world state (first private tx ever). | ||
*/ | ||
throw new IllegalStateException( | ||
"Private world state not available for public world state root hash " + publicBlockHash); | ||
} | ||
return maybePrivateWorldState.get(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...yperledger/besu/ethereum/worldstate/GoQuorumMutablePrivateAndPublicWorldStateUpdater.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* 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.worldstate; | ||
|
||
import org.hyperledger.besu.ethereum.core.Address; | ||
import org.hyperledger.besu.ethereum.core.EvmAccount; | ||
import org.hyperledger.besu.ethereum.core.WorldUpdater; | ||
|
||
// This class uses a public WorldUpdater and a private WorldUpdater to provide a | ||
// MutableWorldStateUpdater that can read and write from BOTH the private world state and the public | ||
// world state. | ||
public class GoQuorumMutablePrivateAndPublicWorldStateUpdater | ||
extends GoQuorumMutablePrivateWorldStateUpdater { | ||
|
||
public GoQuorumMutablePrivateAndPublicWorldStateUpdater( | ||
final WorldUpdater publicWorldUpdater, final WorldUpdater privateWorldUpdater) { | ||
super(publicWorldUpdater, privateWorldUpdater); | ||
} | ||
|
||
@Override | ||
public EvmAccount getAccount(final Address address) { | ||
final EvmAccount privateAccount = privateWorldUpdater.getAccount(address); | ||
if (privateAccount != null && !privateAccount.isEmpty()) { | ||
return privateAccount; | ||
} | ||
final EvmAccount publicAccount = publicWorldUpdater.getAccount(address); | ||
if (publicAccount != null && !publicAccount.isEmpty()) { | ||
return publicAccount; | ||
} | ||
return privateAccount; | ||
} | ||
} |