diff --git a/contracts/.env.example b/contracts/.env.example index 2000284fd..0ff8d6387 100644 --- a/contracts/.env.example +++ b/contracts/.env.example @@ -7,6 +7,8 @@ USER_REGISTRY_TYPE=simple BRIGHTID_CONTEXT=clr.fund # BrightId node addr that signs verifications. Node One uses this one BRIGHTID_VERIFIER_ADDR=0xb1d71F62bEe34E9Fc349234C201090c33BCdF6DB +# The contract that emits the sponsor events that the BrightId node is listening for +BRIGHTID_SPONSOR= # JSON-RPC endpoint to the selected network JSONRPC_HTTP_URL=https://eth-goerli.alchemyapi.io/v2/ADD_API_KEY diff --git a/contracts/tests/round.ts b/contracts/tests/round.ts index 2f76db7c6..cb922080f 100644 --- a/contracts/tests/round.ts +++ b/contracts/tests/round.ts @@ -1329,6 +1329,32 @@ describe('Funding Round', () => { ) ).to.revertedWith('FundingRound: Vote results already verified') }) + + it('returns correct proccessed count in the callback for processing tally results', async () => { + const startIndex = 0 + const batchSize = 10 + let batchCount = 0 + const total = smallTallyTestData.results.tally.length + const lastBatch = Math.ceil(total / batchSize) + await addTallyResultsBatch( + fundingRound.connect(coordinator), + tallyTreeDepth, + smallTallyTestData, + batchSize, + startIndex, + (processed) => { + batchCount++ + if (batchCount === lastBatch) { + expect(processed).to.equal(total, 'Incorrect last batch count') + } else { + expect(processed).to.equal( + batchCount * batchSize, + 'Incorrect proccesed count' + ) + } + } + ) + }) }) describe('getRecipientTallyResultsBatch', () => { diff --git a/contracts/utils/maci.ts b/contracts/utils/maci.ts index 0f80d27f2..62af5db3d 100644 --- a/contracts/utils/maci.ts +++ b/contracts/utils/maci.ts @@ -203,7 +203,10 @@ export async function addTallyResultsBatch( const tx = await fundingRound.addTallyResultsBatch(...data) const receipt = await tx.wait() if (callback) { - callback(i + batchSize, receipt) + // the 2nd element in the data array has the array of + // recipients to be processed for the batch + const totalProcessed = i + data[1].length + callback(totalProcessed, receipt) } totalGasUsed = totalGasUsed.add(receipt.gasUsed) } diff --git a/docs/tally-verify.md b/docs/tally-verify.md index 6a4e2ecd3..9d117e3bd 100644 --- a/docs/tally-verify.md +++ b/docs/tally-verify.md @@ -33,6 +33,7 @@ The contract deployment scripts, `deploy*.ts` in the [clrfund repository](https: ``` ### Recompile the contracts: +Compile the contracts to generate the ABI that the MACI command lines use in the next step. ``` cd ../contracts @@ -40,6 +41,7 @@ npm run compileSol ``` ### Generate coordinator key +Generate the coordinator key used to encrypt messages. The key will be used when deploying new round. ``` cd ../cli @@ -64,31 +66,33 @@ node build/index.js fetchLogs \ --output logs ``` -Decrypt messages and tally the votes: +Decrypt messages, tally the votes and generate proofs: ``` -node build/index.js proveOnChain \ +node build/index.js genProofs \ --eth-provider \ --contract \ --privkey \ - --output proofs.json \ - --tally-file tally.json + --tally-file tally.json \ + --logs-file logs \ + --macistate macistate \ + --output proofs.json ``` -Coordinator private key must be in MACI key format (starts with `macisk`). -Ethereum private key can be any private key that controls the necessary amount of ETH to pay for gas. +The coordinator private key (`COORDINATOR_PRIVKEY`) must be in the MACI key format (starts with `macisk`). It is used to decrypt messages. -The `genProofs` command will create two files: `proofs.json` and `tally.json`. The `proofs.json` file will be needed to run the next command which submits proofs to MACI contract: +The `genProofs` command will create two files: `proofs.json` and `tally.json`. The `proofs.json` file will be needed to run the next command, `proveOnChain`, which submits proofs to the MACI contract: ``` node build/index.js proveOnChain \ --eth-provider \ --contract \ - --privkey \ --eth-privkey \ --proof-file proofs.json ``` +The Ethereum private key (`eth-private-key`) can be any private key that controls the necessary amount of ETH to pay for gas. + The process may take several hours. Results can be found in `tally.json` file, which must then be published via IPFS. Finally, the [CID](https://ipfs.io/ipns/docs.ipfs.io/concepts/content-addressing/) of tally file must be submitted to `FundingRound` contract: