Skip to content

Commit

Permalink
Add logic to check for changed verification flow
Browse files Browse the repository at this point in the history
  • Loading branch information
DOBEN committed Aug 4, 2024
1 parent 5b7a20f commit e972cb3
Show file tree
Hide file tree
Showing 6 changed files with 273 additions and 119 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/docker-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:

pull_request:
branches: main

workflow_dispatch: # allows manual trigger

jobs:
Expand All @@ -24,20 +24,20 @@ jobs:
- {dir: simpleAgeVerification, dockerfile: Dockerfile}
- {dir: ., dockerfile: sponsoredTransactions/Dockerfile}
- {dir: ., dockerfile: sponsoredTransactionsAuction/Dockerfile}

steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive

- name: Build image
working-directory: ${{ matrix.image.dir }}
run:
docker build -f ${{ matrix.image.dockerfile }} .

compose-build:
name: Building with docker-compose
name: Building with docker compose
# Don't run on draft pull requests
if: ${{ !github.event.pull_request.draft }}
runs-on: ubuntu-latest
Expand All @@ -47,11 +47,11 @@ jobs:
with:
submodules: recursive

- name: Build with docker-compose
- name: Build with docker compose
working-directory: trackAndTrace
env:
# Dummy values set because `docker-compose build` enforces the variables only needed on runtime when building.
# Dummy values set because `docker compose build` enforces the variables only needed on runtime when building.
TRACK_AND_TRACE_CONTRACT_ADDRESS: "<8351,0>"
TRACK_AND_TRACE_PRIVATE_KEY_FILE: "./trackAndTrace/README.md"
run:
docker-compose build
docker compose build
4 changes: 4 additions & 0 deletions compliant-reward-distribution/indexer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ curl -POST "http://localhost:8080/api/postTwitterPostLink" -H "Content-Type: app
curl -POST "http://localhost:8080/api/getAccountData" -H "Content-Type: application/json" --data '{"accountAddress":"3cGEB7tTdQBFxJ9sn5JyGPNay2MSmRSKm4133UVqmKoFg4MXJ1","signingData":{"signer":"47b6Qe2XtZANHetanWKP1PbApLKtS3AyiCtcXaqLMbypKjCaRw","message":{"blockHash":"4e68a9f9a671f4b62963cbade295c1b47b74838dabf78c451740c1e060ab0069","blockHeight":3},"signature":"4e68a9f9a671f4b62963cbade295c1b47b74838dabf78c451740c1e060ab00694e68a9f9a671f4b62963cbade295c1b47b74838dabf78c451740c1e060ab0069"}}' -v
```

```
curl -POST "http://localhost:8080/api/getPendingApprovals" -H "Content-Type: application/json" --data '{"limit":10,"offset":0,"signingData":{"signer":"47b6Qe2XtZANHetanWKP1PbApLKtS3AyiCtcXaqLMbypKjCaRw","message":{"blockHash":"4e68a9f9a671f4b62963cbade295c1b47b74838dabf78c451740c1e060ab0069","blockHeight":3},"signature":"4e68a9f9a671f4b62963cbade295c1b47b74838dabf78c451740c1e060ab00694e68a9f9a671f4b62963cbade295c1b47b74838dabf78c451740c1e060ab0069"}}' -v
```

Proof statements:

1.Proof: Reveal "nationalIdNo" proof (Sigma protocol)
Expand Down
59 changes: 25 additions & 34 deletions compliant-reward-distribution/indexer/src/bin/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,48 +198,39 @@ async fn main() -> anyhow::Result<()> {
.await
.context("Could not get database connection from pool")?;

// If the indexer is started for the first time, lookup the last block finalized and initialize
// the database.
let current_block = consensus_info.last_finalized_block_height;

// This function only sets the settings in the database if they haven't been set before.
// Meaning only if the indexer is run for the first time.
db.init_settings(&consensus_info.genesis_block, current_block)
.await
.context("Could not init settings for database")?;

let settings = db
.get_settings()
.await
.context("Could not get settings from database")?;

let start_block = match settings {
// This check prevents that the indexer is re-started with a node connection
// to mainnet while the database has indexed data from testnet or vice versa.
anyhow::ensure!(
settings.genesis_block_hash == consensus_info.genesis_block,
"Genesis hash from the connected node {} does not match the genesis hash {} found \
in the database",
consensus_info.genesis_block,
settings.genesis_block_hash
);

// Get the block to start indexing from.
let start_block = match settings.latest_processed_block_height {
// If the indexer is re-started with the same database settings,
// it should resume indexing from the `latest_processed_block_height+1` as stored in the
// database.
Some(settings) => {
// This check prevents that the indexer is re-started with a node connection
// to mainnet while the database has indexed data from testnet or vice versa.
anyhow::ensure!(
settings.genesis_block_hash == consensus_info.genesis_block,
"Genesis hash from the connected node {} does not match the genesis hash {} found \
in the database",
consensus_info.genesis_block,
settings.genesis_block_hash
);

// While it is possible to start the indexer and immediately stop the indexer,
// so that the settings are set in the database but no block has been processed
// at all, this edge case is rather theoretical and should not
// happen in practice (the default value here should not happen in practice).
settings.latest_processed_block_height.map_or_else(
// Theoretical edge case: If the latest_processed_block_height is not set, we start from the start_block_height.
|| settings.start_block_height,
// If the latest_processed_block_height is set, we start from the next block.
|latest_processed_block_height| latest_processed_block_height.next(),
)
}
// If the indexer is started for the first time, lookup the last block finalized, initialize
// the database, and start to index at the last finalized block.
None => {
let start_block = consensus_info.last_finalized_block_height;

db.init_settings(&consensus_info.genesis_block, start_block)
.await
.context("Could not init settings for database")?;

start_block
}
Some(processed_block) => processed_block.next(),
// If the indexer is started for the first time, use the current block height.
None => current_block,
};

tracing::info!(
Expand Down
Loading

0 comments on commit e972cb3

Please sign in to comment.