mirror of https://github.com/hyperledger/besu
eth_call now supports GoQuorum private transactions (#1934)
eth_call now supports GoQuorum private transactions Signed-off-by: Sally MacFarlane <sally.macfarlane@consensys.net>pull/1965/head
parent
f25d458345
commit
711bbfbd5e
@ -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(); |
||||||
|
} |
||||||
|
} |
@ -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; |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue