Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.exonum.binding.common.crypto.PublicKey;
import com.exonum.binding.common.hash.HashCode;
import com.exonum.binding.core.service.Configurable;
import com.exonum.binding.core.service.Node;
import com.exonum.binding.core.service.Service;
import com.exonum.binding.core.transaction.RawTransaction;
Expand All @@ -29,7 +30,7 @@
/**
* A simple service for QA purposes.
*/
public interface QaService extends Service {
public interface QaService extends Service, Configurable {

/**
* Creates a new self-signed 'increment counter' transaction and submits
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public List<HashCode> getStateHashes(Snapshot snapshot) {
@Override
public void initialize(Fork fork, Configuration configuration) {
// Init the time oracle
initTimeOracle(fork, configuration);
updateTimeOracle(fork, configuration);

// Add a default counter to the blockchain.
createCounter(DEFAULT_COUNTER_NAME, fork);
Expand All @@ -110,20 +110,6 @@ public void initialize(Fork fork, Configuration configuration) {
createCounter(AFTER_COMMIT_COUNTER_NAME, fork);
}

private void initTimeOracle(Fork fork, Configuration configuration) {
QaSchema schema = createDataSchema(fork);
InitialConfiguration config = configuration.getAsMessage(InitialConfiguration.class);
String timeOracleName = config.getTimeOracleName();
// Check the time oracle name is non-empty.
// We do *not* check if the time oracle is active to (a) allow running this service with
// reduced read functionality without time oracle; (b) testing time schema when it is not
// active.
checkArgument(!Strings.isNullOrEmpty(timeOracleName), "Empty time oracle name: %s",
timeOracleName);
// Save the configuration
schema.timeOracleName().set(timeOracleName);
}

private void createCounter(String name, Fork fork) {
QaSchema schema = createDataSchema(fork);
MapIndex<HashCode, Long> counters = schema.counters();
Expand Down Expand Up @@ -231,4 +217,37 @@ private HashCode submitTransaction(RawTransaction rawTransaction) {
private void checkBlockchainInitialized() {
checkState(node != null, "Service has not been fully initialized yet");
}

@Override
public void verifyConfiguration(Fork fork, Configuration configuration) {
InitialConfiguration config = configuration.getAsMessage(InitialConfiguration.class);
checkConfiguration(config);
}

@Override
public void applyConfiguration(Fork fork, Configuration configuration) {
updateTimeOracle(fork, configuration);
}

private void checkConfiguration(InitialConfiguration config) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we rename InitialConfiguration if it's not necessarily initial?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good observation, thanks, let it be QaConfiguration.

(@ivan-ochc — see the patches to the specification: https://wiki.bf.local/pages/viewpreviousversions.action?pageId=1710016)

String timeOracleName = config.getTimeOracleName();
// Check the time oracle name is non-empty.
// We do *not* check if the time oracle is active to (a) allow running this service with
// reduced read functionality without time oracle; (b) testing time schema when it is not
// active.
checkArgument(!Strings.isNullOrEmpty(timeOracleName), "Empty time oracle name: %s",
timeOracleName);
}

private void updateTimeOracle(Fork fork, Configuration configuration) {
QaSchema schema = createDataSchema(fork);
InitialConfiguration config = configuration.getAsMessage(InitialConfiguration.class);

// Verify the configuration
checkConfiguration(config);

// Save the configuration
String timeOracleName = config.getTimeOracleName();
schema.timeOracleName().set(timeOracleName);
}
}