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

refactor(core): remove unnecessary accumulatorQueue in offchain instance #866

Merged
merged 4 commits into from
Dec 7, 2023

Conversation

baumstern
Copy link
Member

@baumstern baumstern commented Dec 4, 2023

This PR removes the accumulatorQueue from our off-chain MaciState and Poll instances. Given the absence of on-chain gas constraints off-chain, this data structure is redundant. The primary mechanism for state management remains the quinary Merkle tree.

@baumstern baumstern self-assigned this Dec 4, 2023
@baumstern baumstern force-pushed the newstr branch 7 times, most recently from 574df96 to 2138177 Compare December 5, 2023 04:41
@baumstern baumstern changed the title Refactor(MaciState): Decouple State Machine and Controller Components Refactor(core): Remove unnecessary accumulatorQueue in offchain instance Dec 5, 2023
@baumstern baumstern changed the title Refactor(core): Remove unnecessary accumulatorQueue in offchain instance Refactor(core): Remove unnecessary accumulatorQueue in offchain instance Dec 5, 2023
@baumstern baumstern marked this pull request as ready for review December 5, 2023 05:08
@baumstern baumstern requested review from ctrlc03 and 0xmad December 5, 2023 05:08
Copy link
Collaborator

@ctrlc03 ctrlc03 left a comment

Choose a reason for hiding this comment

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

Looks neat! left a few comments here and there, any questions lmk. Great work

core/ts/MaciState.ts Show resolved Hide resolved
core/ts/Poll.ts Show resolved Hide resolved
core/ts/Poll.ts Show resolved Hide resolved
core/ts/__tests__/MaciState.test.ts Outdated Show resolved Hide resolved
MaciState,
packProcessMessageSmallVals,
unpackProcessMessageSmallVals,
} from "../";
Copy link
Collaborator

Choose a reason for hiding this comment

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

I've seen you using a mix of ways of importing, for instance within Poll and MaciState you import from the actual file (i.e. import {x} from ./utils/utils) and here you import directly everything from index.ts -> Please make sure it's all consistent (not sure if anyone has a preference here on whether to import from index or from the actual file from within the same package so I'll leave that up to you to decide/find out)

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, I've been importing directly from the actual path when it's within the same package, but for external packages, I thought referencing from index.ts was the standard approach. I've also treated test files as external, even though they're in the same package directory. However, I'm not entirely certain about the most idiomatic way to handle imports in JS🤔

Copy link
Collaborator

Choose a reason for hiding this comment

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

@0xmad what's your take here on what's the most appropriate way to deal with imports?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Here we need to be careful because index import usually produce cycle dependencies. From my experience, we had test forlder for each module/component and just imported from index file.

core/ts/__tests__/MaciState.test.ts Outdated Show resolved Hide resolved
core/ts/__tests__/MaciState.test.ts Show resolved Hide resolved
core/README.md Show resolved Hide resolved
contracts/ts/genMaciState.ts Show resolved Hide resolved
circuits/ts/__tests__/ProcessMessages.test.ts Outdated Show resolved Hide resolved
@baumstern baumstern force-pushed the newstr branch 3 times, most recently from 172ce79 to 464487f Compare December 5, 2023 14:08
@baumstern
Copy link
Member Author

@ctrlc03 Thanks for the review! I've made the revisions you suggested. Please take another look

@0xmad 0xmad changed the title Refactor(core): Remove unnecessary accumulatorQueue in offchain instance refactor(core): Remove unnecessary accumulatorQueue in offchain instance Dec 5, 2023
@0xmad 0xmad changed the title refactor(core): Remove unnecessary accumulatorQueue in offchain instance refactor(core): remove unnecessary accumulatorQueue in offchain instance Dec 5, 2023
core/ts/Poll.ts Outdated
@@ -31,7 +30,6 @@ const blankStateLeafHash = blankStateLeaf.hash();
interface IPoll {
topupMessage(_message: Message): void;
publishMessage(_message: Message, _encPubKey: PubKey): void;
mergeAllMessages(): void;
hasUnprocessedMessages(): boolean;
processMessages(_pollId: number): unknown;
Copy link
Collaborator

Choose a reason for hiding this comment

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

hadn't noticed this before, but it should not be unknown, it can cause issues on other packages that depend on it

Copy link
Collaborator

Choose a reason for hiding this comment

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

also it looks that some functions are set to return void like tallyVotes - for now maybe just add any before we create better typings?

example of what went wrong on another PR due to this:

 ts/__tests__/TallyVotes.test.ts(119,63): error TS2339: Property 'length' does not exist on type 'unknown'.

That is using the return value of tallyVotes (the circuit inputs)

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure thing

Copy link

netlify bot commented Dec 7, 2023

Deploy Preview for maci-typedoc ready!

Name Link
🔨 Latest commit 0588ef6
🔍 Latest deploy log https://app.netlify.com/sites/maci-typedoc/deploys/65712c3a6559310008d4a1d5
😎 Deploy Preview https://deploy-preview-866--maci-typedoc.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@baumstern
Copy link
Member Author

@ctrlc03 Please take another look!

Copy link
Collaborator

@ctrlc03 ctrlc03 left a comment

Choose a reason for hiding this comment

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

Thanks for applying changes, LGTM

@ctrlc03 ctrlc03 merged commit 477368c into dev Dec 7, 2023
14 checks passed
@ctrlc03 ctrlc03 deleted the newstr branch December 7, 2023 10:33
@baumstern baumstern added this to the MACI v1.1.1 refactor milestone Dec 8, 2023
@baumstern baumstern linked an issue Dec 8, 2023 that may be closed by this pull request
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Core package refactoring
3 participants