Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tally - do not fetch logs if tally hash was published #710

Merged
merged 1 commit into from
Aug 21, 2023
Merged
Changes from all 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
45 changes: 28 additions & 17 deletions contracts/tasks/tally.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type TallyArgs = {
maciStateFile: string
providerUrl: string
voteOptionTreeDepth: number
shouldFetchLogs: boolean
}

async function main(args: TallyArgs) {
Expand All @@ -48,17 +49,42 @@ async function main(args: TallyArgs) {
maciStateFile,
providerUrl,
voteOptionTreeDepth,
shouldFetchLogs,
startBlock,
numBlocksPerRequest,
} = args

console.log('funding round address', fundingRound.address)
const maciAddress = await fundingRound.maci()
console.log('maci address', maciAddress)

const publishedTallyHash = await fundingRound.tallyHash()
console.log('publishedTallyHash', publishedTallyHash)

let tally

if (!publishedTallyHash) {
const maciAddress = await fundingRound.maci()
console.log('maci address', maciAddress)

if (shouldFetchLogs) {
// Fetch Maci logs
console.log('Fetching MACI logs from block', startBlock)
try {
await fetchLogs({
contract: maciAddress,
eth_provider: providerUrl,
privkey: coordinatorMaciPrivKey,
start_block: startBlock,
num_blocks_per_request: numBlocksPerRequest,
output: logsFile,
})
console.log('MACI logs generated at', logsFile)
} catch (err) {
console.log('Failed to fetchLogs', err)
throw err
}
}

// Process messages and tally votes
const results = await genProofs({
contract: maciAddress,
Expand Down Expand Up @@ -210,22 +236,6 @@ task('tally', 'Tally votes for the current round')

const timeMs = new Date().getTime()
const logsFile = maciLogs ? maciLogs : `maci_logs_${timeMs}.json`
if (!maciLogs) {
const maciAddress = await fundingRound.maci()
console.log('maci address', maciAddress)

// Fetch Maci logs
console.log('Fetching MACI logs from block', startBlock)
await fetchLogs({
contract: maciAddress,
eth_provider: (network.config as any).url,
privkey: coordinatorMaciPrivKey,
start_block: startBlock,
num_blocks_per_request: numBlocksPerRequest,
output: logsFile,
})
console.log('MACI logs generated at', logsFile)
}

await main({
fundingRound,
Expand All @@ -237,6 +247,7 @@ task('tally', 'Tally votes for the current round')
voteOptionTreeDepth: Number(voteOptionTreeDepth),
logsFile,
providerUrl,
shouldFetchLogs: !maciLogs,
maciStateFile: maciStateFile
? maciStateFile
: `maci_state_${timeMs}.json`,
Expand Down
Loading