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

stack underflow in trie #146

Closed
TimDaub opened this issue Sep 9, 2024 · 1 comment
Closed

stack underflow in trie #146

TimDaub opened this issue Sep 9, 2024 · 1 comment

Comments

@TimDaub
Copy link
Member

TimDaub commented Sep 9, 2024

[1] Stack Trace: Error: You must mint the Kiwi NFT to upvote and submit!
[1]     at _add (file:///Users/timdaub/Projects/attestate/kiwistand/src/store.mjs:396:11)
[1]     at asyncWrapper (/Users/timdaub/Projects/attestate/kiwistand/node_modules/fastq/queue.js:235:12)
[1]     at push (/Users/timdaub/Projects/attestate/kiwistand/node_modules/fastq/queue.js:131:14)
[1]     at /Users/timdaub/Projects/attestate/kiwistand/node_modules/fastq/queue.js:254:7
[1]     at new Promise (<anonymous>)
[1]     at Object.push (/Users/timdaub/Projects/attestate/kiwistand/node_modules/fastq/queue.js:253:13)
[1]     at Module.add (file:///Users/timdaub/Projects/attestate/kiwistand/src/store.mjs:360:22)
[1]     at put (file:///Users/timdaub/Projects/attestate/kiwistand/src/sync.mjs:337:19)
[1]     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
[1]     at async file:///Users/timdaub/Projects/attestate/kiwistand/src/sync.mjs:458:7
[1]     at async file:///Users/timdaub/Projects/attestate/kiwistand/src/sync.mjs:389:18
[1] 2024-09-09T15:38:53.715Z @attestate/kiwistand Attempting to store message with index "66d065b901d62e385338b3bcf4e173f7a3ba9ea34bbd64cd2332bbbd51289c9350300b88" and message: "{"href":"https://longform.asmartbear.com/reputation/","signature":"0xd53711394867b8393a3c6c961ff8da2c4c88db97a047bce8c780f7436352d1e451aaa99c2af046f0f7878995ed04393937c215bac562def00879328bad26e2401c","timestamp":1724933561,"title":"Reputation isn’t as powerful as you imagine","type":"amplify"}"
[1] 2024-09-09T15:38:53.715Z @attestate/kiwistand trie.put failed with "Error: Stack underflow". Successfully rolled back constraint
[1] Message: put: Didn't add message to database
[1] Stack Trace: Error: trie.put failed with "Error: Stack underflow". Successfully rolled back constraint
[1]     at atomicPut (file:///Users/timdaub/Projects/attestate/kiwistand/src/store.mjs:318:11)
[1]     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
[1]     at async _add (file:///Users/timdaub/Projects/attestate/kiwistand/src/store.mjs:438:32)
@TimDaub
Copy link
Member Author

TimDaub commented Sep 10, 2024

[1] 2024-09-10T11:15:36.809Z @attestate/kiwistand Attempting to store message with index "66e01e4214a0a5d430ffe56026c8700b161a11a32bb14be262922996e94efa306a9efdc9" and message: "{"href":"https://www.dejobaan.com/blog/an-ai-that-raps-about-games","signature":"0x840cdc4e4e248800ca350e89e44508c7fb41ac4b2f979d6b0ca2f2d2bfb8fb875bf17d3b68f44eeb12b915eccf7f2149466f046d902ecc97866f39c72b387abf1c","timestamp":1725963842,"title":"Rapping About What’s On Steam","type":"amplify"}"
[1] 2024-09-10T11:15:36.809Z @attestate/kiwistand Message with marker "0xD01559BB03cc83d4661193b513e5A083Ad0cc8Cf|https://dejobaan.com/blog/an-ai-that-raps-about-games|amplify" doesn't pass legitimacy criteria (duplicate). It was probably submitted and accepted before.
[1] Message: put: Didn't add message to database
[1] Stack Trace: Error: Message with marker "0xD01559BB03cc83d4661193b513e5A083Ad0cc8Cf|https://dejobaan.com/blog/an-ai-that-raps-about-games|amplify" doesn't pass legitimacy criteria (duplicate). It was probably submitted and accepted before.
[1]     at atomicPut (file:///Users/timdaub/Projects/attestate/kiwistand/src/store.mjs:280:13)
[1]     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
[1]     at async _add (file:///Users/timdaub/Projects/attestate/kiwistand/src/store.mjs:471:32)
[1]     at async Module.add (file:///Users/timdaub/Projects/attestate/kiwistand/src/store.mjs:392:10)
[1]     at async put (file:///Users/timdaub/Projects/attestate/kiwistand/src/sync.mjs:337:7)
[1]     at async file:///Users/timdaub/Projects/attestate/kiwistand/src/sync.mjs:458:7
[1]     at async file:///Users/timdaub/Projects/attestate/kiwistand/src/sync.mjs:389:18
[1] 2024-09-10T11:15:36.809Z @attestate/kiwistand Calling trie commit, and saving root: 8744dd06af45097295c556ab4a9526b0be21ca01c04f607c4f2b866b0049c843
[1] 2024-09-10T11:15:36.880Z @attestate/kiwistand Unsetting global peer
[1] 2024-09-10T11:15:37.443Z @attestate/kiwistand Setting global peer: "16Uiu2HAmFzqeeF18eXy4SRTN79Y6DkPgFjx8qJf2LmY4K35dR52K"
[1] 2024-09-10T11:15:37.443Z @attestate/kiwistand handleLeaves: Received leaves and storing them in db
[1] 2024-09-10T11:15:37.486Z @attestate/kiwistand Attempting to store message with index "643c442d5c608bd8d22bc947ed18f513d3c0e9df97861190fa556f1138511faddf14e782" and message: "{"href":"https://craigmod.com/essays/fast_software/","signature":"0x6a4861e03540a4ee0daf113c37a1d513ae3015657046438e3da9d14ac9bf46991efce10587d280f7996115e372cb73ecaa23fd694c5597c03a8a12041dfd3faa1c","timestamp":1681671213,"title":"Fast Software, the Best Software","type":"amplify"}"
[1] 2024-09-10T11:15:37.487Z @attestate/kiwistand trie.put failed with "Error: Stack underflow
[1]     at Trie._updateNode (/Users/timdaub/Projects/attestate/kiwistand/node_modules/@ethereumjs/trie/dist/trie/trie.js:325:19)
[1]     at Trie.put (/Users/timdaub/Projects/attestate/kiwistand/node_modules/@ethereumjs/trie/dist/trie/trie.js:158:24)
[1]     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
[1]     at async atomicPut (file:///Users/timdaub/Projects/attestate/kiwistand/src/store.mjs:288:5)
[1]     at async _add (file:///Users/timdaub/Projects/attestate/kiwistand/src/store.mjs:471:32)
[1]     at async Module.add (file:///Users/timdaub/Projects/attestate/kiwistand/src/store.mjs:392:10)
[1]     at async put (file:///Users/timdaub/Projects/attestate/kiwistand/src/sync.mjs:337:7)
[1]     at async file:///Users/timdaub/Projects/attestate/kiwistand/src/sync.mjs:458:7
[1]     at async file:///Users/timdaub/Projects/attestate/kiwistand/src/sync.mjs:389:18". Successfully rolled back constraint
[1] Message: put: Didn't add message to database
[1] Stack Trace: Error: trie.put failed with "Error: Stack underflow
[1]     at Trie._updateNode (/Users/timdaub/Projects/attestate/kiwistand/node_modules/@ethereumjs/trie/dist/trie/trie.js:325:19)
[1]     at Trie.put (/Users/timdaub/Projects/attestate/kiwistand/node_modules/@ethereumjs/trie/dist/trie/trie.js:158:24)
[1]     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
[1]     at async atomicPut (file:///Users/timdaub/Projects/attestate/kiwistand/src/store.mjs:288:5)
[1]     at async _add (file:///Users/timdaub/Projects/attestate/kiwistand/src/store.mjs:471:32)
[1]     at async Module.add (file:///Users/timdaub/Projects/attestate/kiwistand/src/store.mjs:392:10)
[1]     at async put (file:///Users/timdaub/Projects/attestate/kiwistand/src/sync.mjs:337:7)
[1]     at async file:///Users/timdaub/Projects/attestate/kiwistand/src/sync.mjs:458:7
[1]     at async file:///Users/timdaub/Projects/attestate/kiwistand/src/sync.mjs:389:18". Successfully rolled back constraint
[1]     at atomicPut (file:///Users/timdaub/Projects/attestate/kiwistand/src/store.mjs:329:11)
[1]     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
[1]     at async _add (file:///Users/timdaub/Projects/attestate/kiwistand/src/store.mjs:471:32)
[1]     at async Module.add (file:///Users/timdaub/Projects/attestate/kiwistand/src/store.mjs:392:10)
[1]     at async put (file:///Users/timdaub/Projects/attestate/kiwistand/src/sync.mjs:337:7)
[1]     at async file:///Users/timdaub/Projects/attestate/kiwistand/src/sync.mjs:458:7

TimDaub added a commit that referenced this issue Sep 10, 2024
For months now the reconciliation algo has been plagued by bugs
surrounding the ethereumjs/trie library. We've opened many tickets on
Github:

- #146
- #131
- ethereumjs/ethereumjs-monorepo#3264
- ethereumjs/ethereumjs-monorepo#3645

The pattern of the problem was always that somehow that `trie.root()`
couldn't be found using `trie.checkRoot`, which seemed almost like a
contradiction, especially when doing `await
trie.checkRoot(trie.root())`.

We had initially introduced the checkpointing of the trie because of
some rather theoretical problem regarding what would happen if during
the reconciliation the trie updates and, at the same times, sends level
comparisons to a peer. So to use checkpointing for us was primarily used
to implement atomicity when storing data. We wanted to just store the
remote trie's leaves in batches as to make sure not to interrupt the
algorithm to compare the trie's levels.

At the same time, the insertion of new leaves into such a trie is costly
as a big part of its hashes have to be recomputed to arrive at a new
root.

However, I think what has happened with our implementation of the
sync.put method is that the checkpointing led to the trie writes not
being processed sequentially which also lead to all sorts of problems
in the reconciliation.

The reconciliation is purposefully built in a way where it first
synchronizes old leaves and only then new leaves. While a working
reconciliation doesn't have any issues with storing comments, a
fundamentally asynchronous reconciliation will attempt to store comments
where the original upvote hasn't been made yet, leading to the message
not being processed initially.

Another big problem ended up being that the ethereumjs/trie library
isn't mature with regards to handling the application shutting down, and
so a lot of the above mentioned issues actually describe the
ethereumjs/trie library reaching a non-recoverable state.

Funnily enough, however, all it took to fix all of the above problems
was to remove all notions of checkpointing and commits. While it does
make the reconciliation algorithm MUCH slower (because it is now
synchronous), it also made it much more reliable and almost free of
errors during interaction.
@TimDaub TimDaub closed this as completed Sep 10, 2024
TimDaub added a commit that referenced this issue Sep 11, 2024
For months now the reconciliation algo has been plagued by bugs
surrounding the ethereumjs/trie library. We've opened many tickets on
Github:

- #146
- #131
- ethereumjs/ethereumjs-monorepo#3264
- ethereumjs/ethereumjs-monorepo#3645

The pattern of the problem was always that somehow that `trie.root()`
couldn't be found using `trie.checkRoot`, which seemed almost like a
contradiction, especially when doing `await
trie.checkRoot(trie.root())`.

We had initially introduced the checkpointing of the trie because of
some rather theoretical problem regarding what would happen if during
the reconciliation the trie updates and, at the same times, sends level
comparisons to a peer. So to use checkpointing for us was primarily used
to implement atomicity when storing data. We wanted to just store the
remote trie's leaves in batches as to make sure not to interrupt the
algorithm to compare the trie's levels.

At the same time, the insertion of new leaves into such a trie is costly
as a big part of its hashes have to be recomputed to arrive at a new
root.

However, I think what has happened with our implementation of the
sync.put method is that the checkpointing led to the trie writes not
being processed sequentially which also lead to all sorts of problems
in the reconciliation.

The reconciliation is purposefully built in a way where it first
synchronizes old leaves and only then new leaves. While a working
reconciliation doesn't have any issues with storing comments, a
fundamentally asynchronous reconciliation will attempt to store comments
where the original upvote hasn't been made yet, leading to the message
not being processed initially.

Another big problem ended up being that the ethereumjs/trie library
isn't mature with regards to handling the application shutting down, and
so a lot of the above mentioned issues actually describe the
ethereumjs/trie library reaching a non-recoverable state.

Funnily enough, however, all it took to fix all of the above problems
was to remove all notions of checkpointing and commits. While it does
make the reconciliation algorithm MUCH slower (because it is now
synchronous), it also made it much more reliable and almost free of
errors during interaction.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant