Skip to content

Commit

Permalink
Merge pull request #1042 from HorizenOfficial/st/preimages
Browse files Browse the repository at this point in the history
St/preimages
  • Loading branch information
paolocappelletti authored Jun 25, 2024
2 parents 5dac3e7 + 5c2724e commit a200127
Show file tree
Hide file tree
Showing 15 changed files with 75 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
**0.13.0**
1. Enabling preimages configuration

**0.12.0**
1. Sparkz dependency updated to 2.4.0
* Updates in EON forger nodes connection policy (see release notes for further info)
Expand Down
1 change: 1 addition & 0 deletions doc/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Horizen Sidechain SDK Release Notes

## Version [0.13.0](/doc/release/0.13.0.md)
## Version [0.12.0](/doc/release/0.12.0.md)
## Version [0.11.0](/doc/release/0.11.0.md)
## Version [0.10.1](/doc/release/0.10.1.md)
Expand Down
30 changes: 30 additions & 0 deletions doc/release/0.13.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Release notes - version 0.13.0

---

## Notes about new/updated Features

### Preimages enabling
A new property was added to the config file for enabling the storage of preimages. Preimages contain the account
addresses that are not usually saved in the state trie. Enabling preimages is a pre-requirement for executing a state dump.

How to specify it:
- inside the config file, add a property like this inside the *evmStateDump* section:

enabled = "true"


---
## Bug Fixes

---

## Improvements

---
## Update test instructions from previous version


---
Full [Changelog](/CHANGELOG.md) file here

6 changes: 4 additions & 2 deletions qa/SidechainTestFramework/sc_boostrap_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ def __init__(self,
max_mempool_slots=DEFAULT_MAX_MEMPOOL_SLOTS,
max_nonexec_pool_slots=DEFAULT_MAX_NONEXEC_POOL_SLOTS,
tx_lifetime=DEFAULT_TX_LIFETIME,
handling_txs_enabled=True
handling_txs_enabled=True,
evm_state_dump_enabled=True

):
if submitter_private_keys_indexes is None:
Expand Down Expand Up @@ -193,7 +194,8 @@ def __init__(self,
self.max_mempool_slots = max_mempool_slots
self.max_nonexec_pool_slots = max_nonexec_pool_slots
self.tx_lifetime = tx_lifetime
self.handling_txs_enabled=handling_txs_enabled
self.handling_txs_enabled = handling_txs_enabled
self.evm_state_dump_enabled = evm_state_dump_enabled


def update_websocket_config(self, websocket_server_enabled, websocket_server_port):
Expand Down
3 changes: 2 additions & 1 deletion qa/SidechainTestFramework/scutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,8 @@ def initialize_sc_datadir(dirname, n, model, bootstrap_info=SCBootstrapInfo, sc_
'MAX_NONEXEC_SLOTS': sc_node_config.max_nonexec_pool_slots,
'TX_LIFETIME': sc_node_config.tx_lifetime,
'HANDLING_TXS_ENABLED': ("true" if sc_node_config.handling_txs_enabled else "false"),
'FORGER_REWARD_ADDRESS': sc_node_config.forger_options.forger_reward_address
'FORGER_REWARD_ADDRESS': sc_node_config.forger_options.forger_reward_address,
'EVM_STATE_DUMP_ENABLED': ("true" if sc_node_config.evm_state_dump_enabled else "false"),

}
config = config.replace("'", "")
Expand Down
4 changes: 4 additions & 0 deletions qa/resources/template.conf
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,8 @@ sparkz {
txLifetime = %(TX_LIFETIME)d seconds
allowUnprotectedTxs = %(ALLOW_UNPROTECTED_TXS)s
}

evmStateDump {
enabled = %(EVM_STATE_DUMP_ENABLED)s
}
}
2 changes: 1 addition & 1 deletion sdk/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@
<dependency>
<groupId>io.horizen</groupId>
<artifactId>libevm</artifactId>
<version>1.1.0</version>
<version>1.2.0-snapshot</version>
</dependency>
<dependency>
<groupId>at.favre.lib</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,8 @@ abstract class AbstractSidechainNodeViewHolder[
if (!history().contains(pmod.id)) {
context.system.eventStream.publish(StartingPersistentModifierApplication(pmod))

log.info(s"Apply modifier ${pmod.encodedId} of type ${pmod.modifierTypeId} to nodeViewHolder")
log.info(s"Apply modifier ${pmod.encodedId} of type ${pmod.modifierTypeId} to nodeViewHolder" +
{if (sidechainSettings.evmStateDump.enabled) ", state dump enabled" else ""})

history().append(pmod) match {
case Success((historyBeforeStUpdate, progressInfo)) =>
Expand Down
13 changes: 12 additions & 1 deletion sdk/src/main/scala/io/horizen/SidechainSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,22 @@ case class HistorySettings(
resetModifiersStatus: Boolean = false,
)


case class MetricsApiSettings(
enabled: Boolean,
bindAddress: InetSocketAddress,
apiKeyHash: Option[String],
corsAllowedOrigin: Option[String],
timeout: FiniteDuration) extends ApiSettings

case class EvmStateDump(

/**
* If true, enable collecting preimages, that is a pre-requirement for the state dump
*/
enabled: Boolean = false,
)

case class SidechainSettings(
sparkzSettings: SparkzSettings,
metricsSettings: MetricsApiSettings,
Expand All @@ -182,7 +192,8 @@ case class SidechainSettings(
ethService: EthServiceSettings,
accountMempool: AccountMempoolSettings,
apiRateLimiter: ApiRateLimiterSettings,
history: HistorySettings
history: HistorySettings,
evmStateDump: EvmStateDump
){
require(sparkzSettings.network.handlingTransactionsEnabled || !forger.automaticForging,
s"Node that does not support transaction handling cannot be a forger node: " +
Expand Down
3 changes: 2 additions & 1 deletion sdk/src/main/scala/io/horizen/SidechainSettingsReader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@ object SidechainSettingsReader
val ethServiceSettings = config.as[EthServiceSettings]("sparkz.ethService")
val apiRateLimiterSettings = config.as[ApiRateLimiterSettings]("sparkz.apiRateLimiter")
val historySettings = config.as[HistorySettings]("sparkz.history")
val evmStateDumpSettings = config.as[EvmStateDump]("sparkz.evmStateDump")

SidechainSettings(sparkzSettings, metricsSettings, genesisSettings, webSocketClientSettings, webSocketServerSettings, certificateSettings,
remoteKeysManagerSettings, mempoolSettings, walletSettings, forgerSettings, cswSettings, logInfoSettings,
ethServiceSettings, accountMempoolSettings, apiRateLimiterSettings, historySettings)
ethServiceSettings, accountMempoolSettings, apiRateLimiterSettings, historySettings, evmStateDumpSettings)
}

def readConfigFromPath(userConfigPath: String, applicationConfigPath: Option[String]): Config = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ class AccountSidechainApp @Inject()
protected val stateMetadataStorage = new AccountStateMetadataStorage(
registerClosableResource(new VersionedLevelDbStorageAdapter(metaStateStore, params.maxHistoryRewritingLength * 2)))

protected val stateDbStorage: LevelDBDatabase = registerClosableResource(new LevelDBDatabase(dataDirAbsolutePath + "/evm-state"))
protected val stateDbStorage: LevelDBDatabase = registerClosableResource(new LevelDBDatabase(dataDirAbsolutePath + "/evm-state",
sidechainSettings.evmStateDump.enabled))

protected val consensusDataStorage = new ConsensusDataStorage(
registerClosableResource(new VersionedLevelDbStorageAdapter(consensusStore, 5)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ class AccountSidechainNodeViewHolder(sidechainSettings: SidechainSettings,

override def restoreState(): Option[(HIS, MS, VL, MP)] = {
log.info("Restoring persistent state from storage...")
log.info(s"restoreState - state dump enabled: ${sidechainSettings.evmStateDump.enabled}")

val restoredData = for {
history <- AccountHistory.restoreHistory(historyStorage, consensusDataStorage, params, semanticBlockValidators(params), historyBlockValidators(params))
Expand All @@ -141,6 +142,7 @@ class AccountSidechainNodeViewHolder(sidechainSettings: SidechainSettings,
}

override protected def genesisState: (HIS, MS, VL, MP) = {
log.info(s"genesisState - state dump enabled: ${sidechainSettings.evmStateDump.enabled}")
val result = for {
state <- AccountState.createGenesisState(stateMetadataStorage, stateDbStorage, messageProcessors(params), params, timeProvider, blockHashProvider, genesisBlock)
(_: ModifierId, consensusEpochInfo: ConsensusEpochInfo) <- Success(state.getCurrentConsensusEpochInfo)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import io.horizen.metrics.MetricsManager
import io.horizen.params.NetworkParams
import io.horizen.storage.SidechainSecretStorage
import io.horizen.utils.BytesUtils
import io.horizen.{AccountMempoolSettings, SidechainSettings, SidechainTypes, WalletSettings}
import io.horizen.{AccountMempoolSettings, EvmStateDump, SidechainSettings, SidechainTypes, WalletSettings}
import org.junit.Assert.{assertEquals, assertTrue}
import org.junit.{Before, Test}
import org.mockito.{ArgumentMatchers, Mockito}
Expand Down Expand Up @@ -176,6 +176,7 @@ class AccountSidechainNodeViewHolderEventTest
val mockWalletSettings: WalletSettings = mock[WalletSettings]
Mockito.when(mockWalletSettings.maxTxFee).thenReturn(100L)
Mockito.when(sidechainSettings.wallet).thenReturn(mockWalletSettings)
Mockito.when(sidechainSettings.evmStateDump).thenReturn(EvmStateDump(false))
val params: NetworkParams = mock[NetworkParams]
Mockito.when(params.chainId).thenReturn(1997)
Mockito.when(params.circuitType).thenReturn(NaiveThresholdSignatureCircuit)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ trait MockedAccountSidechainNodeViewHolderFixture extends MockitoSugar {
.thenAnswer(_ => {
walletSettings
})
Mockito.when(sidechainSettings.evmStateDump)
.thenAnswer(_ => {
EvmStateDump(false)
})

actorSystem.actorOf(Props(new MockedAccountSidechainNodeViewHolder(sidechainSettings, history, state, wallet, mempool)))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ trait MockedSidechainNodeViewHolderFixture extends MockitoSugar {
.thenAnswer(answer => {
10000000L
})
Mockito.when(sidechainSettings.evmStateDump)
.thenAnswer(_ => {
EvmStateDump(false)
})
actorSystem.actorOf(Props(new MockedSidechainNodeViewHolder(sidechainSettings, history, state, wallet, mempool)))
}

Expand Down

0 comments on commit a200127

Please sign in to comment.