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

Epoch Commitments #2212

Merged
merged 321 commits into from
Jul 5, 2022
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
321 commits
Select commit Hold shift + click to select a range
acb4180
Change diff storage and update it on tx confirmation
daria305 Jun 3, 2022
832ee21
Merge remote-tracking branch 'origin/feat/epoch-commitment' into feat…
daria305 Jun 3, 2022
cd2ae61
Fix snapshot errors after diff store changes
daria305 Jun 3, 2022
db7b3ee
Merge branch 'feat/epoch-commitment' of github.com:iotaledger/goshimm…
karimodm Jun 7, 2022
dc98c0f
types fixes and storage
karimodm Jun 7, 2022
aeff4d9
Revert GetLatestEC
karimodm Jun 7, 2022
d2a666d
Feat: Avoid storing transient UTXOs in epoch diffs #2251
karimodm Jun 7, 2022
2b259cc
Small fixes
karimodm Jun 7, 2022
b191500
Feat: some structures lifecycle
karimodm Jun 7, 2022
fbef94f
Better storage
karimodm Jun 8, 2022
a6dd203
Update the structure
daria305 Jun 8, 2022
cceb0b5
Merge branch 'feat/epoch-commitment' into feat/update-ec-structure
daria305 Jun 8, 2022
fccd6ec
Move epoch package inside ledger. Change OutputMetadata and EpochDiff…
georgysavva Jun 8, 2022
4a7837f
Feat: structures lifecycle
karimodm Jun 8, 2022
b6b7985
Feat: proper getters and setters for storables
karimodm Jun 8, 2022
947d77f
Add TODOs
karimodm Jun 8, 2022
08588d9
Merge branch 'feat/epoch-commitment' into feat/update-ec-structure
daria305 Jun 8, 2022
b25558f
Merge remote-tracking branch 'origin/develop' into feat/epoch-commitment
karimodm Jun 8, 2022
87f9a51
Fix: using new models after merge
karimodm Jun 8, 2022
da505cd
Fix: no compile errors
karimodm Jun 8, 2022
bb51d3e
Fix: storage nil pointer dereference
karimodm Jun 8, 2022
fc8307d
Add commitments progressing when delayed
daria305 Jun 9, 2022
42ffd22
Merge branch 'feat/epoch-commitment' into feat/update-ec-structure
daria305 Jun 9, 2022
6b0cf8a
Add comments to exported methods
jkrvivian Jun 9, 2022
cd1e8b5
Only have one MinMana threshold
karimodm Jun 9, 2022
079a005
Merge branch 'feat/epoch-commitment' of github.com:iotaledger/goshimm…
karimodm Jun 9, 2022
4380699
Change load snapshot logic for mana
georgysavva Jun 9, 2022
c51273d
Make epoch indeces persistent
karimodm Jun 9, 2022
39df69f
Add mana state root
daria305 Jun 9, 2022
3990932
Remove ecc
daria305 Jun 9, 2022
a5e12de
Use CachedECRecord
karimodm Jun 9, 2022
928d349
Merge branch 'feat/epoch-commitment' into feat/add-mana-root
daria305 Jun 9, 2022
f43fb1b
Merge branch 'feat/epoch-commitment' into snapshot-mana-epochs
georgysavva Jun 9, 2022
37ce2a5
Fix merge conflicts
georgysavva Jun 9, 2022
a3bb2f3
Fic EpochDiff definition
georgysavva Jun 9, 2022
3e73aff
Remove mana leaf if balance is 0
daria305 Jun 9, 2022
8ebc0b3
Remove EpochCommitment struct & code duplication
karimodm Jun 9, 2022
a6ae03c
Store latest ECRecord from snapshot
karimodm Jun 9, 2022
07321b7
Merge branch 'feat/epoch-commitment' into snapshot-mana-epochs-genera…
karimodm Jun 9, 2022
22da58f
Update packages/ledger/models.go
georgysavva Jun 9, 2022
7688260
EpochDiff now in ledger package to avoid cycles
karimodm Jun 9, 2022
df6971e
Merge branch 'snapshot-mana-epochs' of github.com:iotaledger/goshimme…
karimodm Jun 9, 2022
3825f8e
Genesis Snapshot Generation
karimodm Jun 9, 2022
840e65f
Merge branch 'feat/epoch-commitment' into feat/add-mana-root
daria305 Jun 9, 2022
d232ebd
AccessMana is now Mana1
karimodm Jun 9, 2022
42d174a
Remove references to --mana.snapshotResetTime=true
karimodm Jun 9, 2022
d546f29
Merge branch 'snapshot-mana-epochs' into feat/accessmana-mana1
karimodm Jun 9, 2022
03e9614
Remove references to --mana.snapshotResetTime=true
karimodm Jun 9, 2022
cda189a
Merge branch 'feat/accessmana-mana1' into feat/snapshot-mana-epochs-g…
karimodm Jun 9, 2022
090d5db
Fix some issues
karimodm Jun 9, 2022
fe263fb
Merge branch 'feat/epoch-commitment' into test-commitment
karimodm Jun 9, 2022
c12ebd6
Review fixes
georgysavva Jun 10, 2022
25beea7
Merge branch 'feat/epoch-commitment' into snapshot-mana-epochs
georgysavva Jun 10, 2022
0f65c0f
Genesis Snapshot Generation (#2266)
karimodm Jun 10, 2022
efdad0f
Remove OracleEpochShift
karimodm Jun 10, 2022
8247123
Fix: always initialize trees on new epoch
karimodm Jun 10, 2022
771763f
Working committments in messages
karimodm Jun 10, 2022
5ebe2e3
AccessMana is now Mana1 (#2267)
karimodm Jun 10, 2022
3a4a766
Add EC related variables to test framework
jkrvivian Jun 10, 2022
f4db46e
Add event mock structure for notarization manager
jkrvivian Jun 10, 2022
5dacd0e
Implement Tangle smt Tree test
jkrvivian Jun 10, 2022
0297231
EpochCommittment in dashboard
karimodm Jun 10, 2022
212cc2e
ECs finally in Messages
karimodm Jun 10, 2022
b56895c
Fixed dashboard LatestConfirmedEpoch glitch
karimodm Jun 10, 2022
938c22f
Fix: correctly compute PrevEC
karimodm Jun 10, 2022
96cc07c
Feat: include computed EC in dashboard
karimodm Jun 10, 2022
862dfae
Remove debugging prints
karimodm Jun 10, 2022
55bd58f
Merge branch 'feat/epoch-commitment' into test/notarization-manager
jkrvivian Jun 10, 2022
0ecbc6c
Update initialize with data method
georgysavva Jun 10, 2022
fe8023d
Snapshot
georgysavva Jun 10, 2022
87bf63a
Merge branch 'feat/epoch-commitment' into snapshot-mana-epochs
georgysavva Jun 10, 2022
832396f
Fix after merge
georgysavva Jun 10, 2022
bc7903c
Revert "Remove debugging prints"
karimodm Jun 10, 2022
dd0769c
Bump hive.go
karimodm Jun 11, 2022
25ddcf6
Several fixes
karimodm Jun 11, 2022
62d910c
Create snapshot in createGenesisOutputs
jkrvivian Jun 13, 2022
0ad47b9
Load snapshot and fix test
jkrvivian Jun 13, 2022
7e95967
Set up Tangle and issue messages
jkrvivian Jun 13, 2022
90b99f1
Fixes
jkrvivian Jun 13, 2022
b53e5b7
Fix a bunch of things
karimodm Jun 13, 2022
0c0111f
Merge pull request #2265 from iotaledger/snapshot-mana-epochs
karimodm Jun 13, 2022
120f372
Temporary Fix: epochdiff loading
karimodm Jun 13, 2022
0d702ab
Bypass finality gadget
jkrvivian Jun 14, 2022
2ff623e
Merge branch 'feat/epoch-commitment' into feat/add-mana-root
daria305 Jun 14, 2022
4c789b9
Fixes after merge
daria305 Jun 14, 2022
ad1dba2
Split EpochDiff storage & several fixes
karimodm Jun 14, 2022
946dfeb
Move store and load diff functions back to commitment factory
karimodm Jun 14, 2022
3fa3930
Update mana trees
daria305 Jun 15, 2022
6d1c636
Solve Update diff storage on inclusion todo
daria305 Jun 15, 2022
fff3aa5
Update diff on the message orphaned event if contain tx
daria305 Jun 15, 2022
2b999ac
Fix epochdiff storage
karimodm Jun 15, 2022
4f87ff4
Remove OnTransactionConfirmed in favor of OnTransactionInclusionUpdated
karimodm Jun 15, 2022
e6a8c0c
Merge remote-tracking branch 'origin/feat/add-mana-root' into feat/sp…
karimodm Jun 15, 2022
1c8f4d1
Rewrite test with TestScenario
jkrvivian Jun 15, 2022
c48bd04
Check CommitmentFunc error and committed epoch EI
jkrvivian Jun 16, 2022
d75d3c2
Working epoch committments with ManaRoot
karimodm Jun 16, 2022
a503124
Move proof stuff to its own file
karimodm Jun 16, 2022
196c418
Add state mutation and PCC tests
jkrvivian Jun 17, 2022
de0401b
Change mutation state test to non-conflicting txs scenario
jkrvivian Jun 17, 2022
2e6b32c
Add debug prints
jkrvivian Jun 17, 2022
db0f244
Remove some TODOs
karimodm Jun 17, 2022
fed2388
Addressed review
karimodm Jun 17, 2022
22c6260
Merge pull request #2291 from iotaledger/feat/split-epochdiff-storage
karimodm Jun 17, 2022
bb2b617
Fix: typos
karimodm Jun 17, 2022
a7e8b71
SnapshotDepth as notarization parameter
karimodm Jun 17, 2022
310fec2
Wire events from within notarization Manager
karimodm Jun 17, 2022
b13f3a0
Fix: do not shutdown Tangle twice
karimodm Jun 17, 2022
e4d4a88
Fix: removed unused mana snapshot
karimodm Jun 17, 2022
092951c
Dockerfile support go.work
karimodm Jun 17, 2022
2c1257e
Fix snapshot mana allocation for integration tests
karimodm Jun 17, 2022
d363d9e
Fix: mana test
karimodm Jun 17, 2022
180afbd
Merge branch 'feat/epoch-commitment' into test/notarization-manager
jkrvivian Jun 17, 2022
f86be7e
Fix Tangle tree test
jkrvivian Jun 20, 2022
e879c9f
Initialize ECRecord in new options
jkrvivian Jun 20, 2022
643fe73
Update State Mutation test to the latest changes
jkrvivian Jun 20, 2022
cd9ab89
Remove OnTransactionConfirmed
jkrvivian Jun 20, 2022
a3eb794
Fix some race conditions
karimodm Jun 20, 2022
d4f847f
Small improvement
karimodm Jun 20, 2022
ef266e8
Fix conflict Transaction Inclusion
karimodm Jun 20, 2022
9230360
Fix storage shutdown
karimodm Jun 20, 2022
953be01
Merge remote-tracking branch 'origin/develop' into fix/integration-tests
karimodm Jun 20, 2022
638c5ce
Fix common tests
karimodm Jun 20, 2022
a298075
Fix missing mana leaf startup error
karimodm Jun 20, 2022
72b4b13
Removed debugging prints
karimodm Jun 20, 2022
37cfcdf
Exported functions first
karimodm Jun 20, 2022
567182b
Fix: attachment might not be booked yet on BranchCreated
karimodm Jun 20, 2022
63d5a01
Use Tangle Time for old enough check
daria305 Jun 21, 2022
7d14eaf
Move Epoch Manager to epoch package
daria305 Jun 21, 2022
c7fe27c
Check if commitment tree exists before generating a proof
jkrvivian Jun 21, 2022
08595b9
Rename newEpochManager
daria305 Jun 21, 2022
641a08e
Fix snapshot creation in TestFramework
karimodm Jun 21, 2022
523d209
Epoch Commitments: fix bugs & integration tests #2297 from iotaledger…
karimodm Jun 21, 2022
58c6832
Merge remote-tracking branch 'origin/feat/epoch-commitment' into feat…
karimodm Jun 21, 2022
7fb2a8b
Merge remote-tracking branch 'origin/develop' into feat/merge-base-de…
karimodm Jun 21, 2022
7e68d36
Merge remote-tracking branch 'origin/test/notarization-manager' into …
karimodm Jun 21, 2022
27e904d
Fixes after merge
karimodm Jun 21, 2022
65f0dac
Merge remote-tracking branch 'origin/feat/epoch-commitment' into test…
karimodm Jun 21, 2022
056c62e
Fixes after merge
karimodm Jun 21, 2022
e83929f
Verify root and msgID/txID
jkrvivian Jun 21, 2022
ec1c29f
pkged.go
karimodm Jun 21, 2022
71d3d29
Disable notarization plugin on entrynode
karimodm Jun 21, 2022
a4e8fb1
Add next epoch started event
daria305 Jun 22, 2022
9b18abf
Merge branch 'feat/epoch-commitment' into feat/add-epoch-committable-…
daria305 Jun 22, 2022
fb409ee
Fix typo
daria305 Jun 22, 2022
b66987f
Remove unnecessary indexes from storage and add new
daria305 Jun 22, 2022
bdd9b9b
Fix and add conflicting test
jkrvivian Jun 22, 2022
1ed2211
Only treat Notarization events when node is bootstrapped
karimodm Jun 23, 2022
785e16c
Initialize aMana from snapshot without epoch delay
karimodm Jun 23, 2022
ce9eac1
Remove EpochManager as it is completely stateless
karimodm Jun 23, 2022
c0e9e86
Properly return or panic when error conditions are detected
karimodm Jun 23, 2022
f8bb143
Drop committmentTrees upon committing an epoch
karimodm Jun 23, 2022
01caec4
Book consensus mana in whole epochs
daria305 Jun 24, 2022
14d1b5a
Refactor testing framework set-up
jkrvivian Jun 24, 2022
2500836
Refactor assert functions
jkrvivian Jun 24, 2022
47d4b0a
Remove proofs code
karimodm Jun 24, 2022
fac32ec
Merge pull request #2310 from iotaledger/feat/epoch-commitment-fixes
karimodm Jun 24, 2022
35d873a
Merge remote-tracking branch 'origin/feat/epoch-commitment' into feat…
karimodm Jun 24, 2022
40c041e
Merge pull request #2309 from iotaledger/feat/move-epochmanager-to-epoch
karimodm Jun 24, 2022
33ebc9e
Ditch TestScenario in testing
jkrvivian Jun 24, 2022
b774ba3
Merge branch 'feat/merge-develop-into-epochs' into feat/epoch-commitment
karimodm Jun 24, 2022
3292b58
Merge remote-tracking branch 'origin/develop' into feat/epoch-commitment
karimodm Jun 24, 2022
e95dcdb
Merge pull request #2304 from iotaledger/feat/epoch-commitment-only-w…
karimodm Jun 24, 2022
f72181e
Merge branch 'feat/epoch-commitment' into feat/add-epoch-committable-…
daria305 Jun 24, 2022
8c85325
Clean up after merge
daria305 Jun 24, 2022
6b03bb7
Only trigger EpochCommitted if newly committed
karimodm Jun 24, 2022
a34277d
WIP: TestManager_DiffUTXOs
karimodm Jun 24, 2022
16d6cd8
Add TransactionInclusionUpdate test
jkrvivian Jun 24, 2022
64e3f04
Add assert diff store function
jkrvivian Jun 25, 2022
bd65e4e
Fix OutputWithMetadata model FromObjectStorage
karimodm Jun 26, 2022
16bd789
Merge branch 'test/notarization-manager' of github.com:iotaledger/gos…
karimodm Jun 26, 2022
73370ef
Fix: properly compact spent/created diff
karimodm Jun 26, 2022
5527fe7
Fix: async diffStorage shutdown in goroutine
karimodm Jun 26, 2022
ea76c9d
DiffUTXO test with reattachment
karimodm Jun 26, 2022
b094f02
Fix: isNew ecRecord
karimodm Jun 26, 2022
e32d180
DiffUTXO test with event expectation
karimodm Jun 26, 2022
da8bc45
Fix all notarization manager tests
karimodm Jun 26, 2022
31dee3f
OutputWithMetadata FromBytes with correct IDs
karimodm Jun 27, 2022
8f5d647
Merge remote-tracking branch 'origin/feat/epoch-commitment' into test…
karimodm Jun 27, 2022
0b21d7a
Some fixes after merge
karimodm Jun 27, 2022
6d30ad2
Compiles again
karimodm Jun 27, 2022
82ece8d
notarization tests passing
karimodm Jun 27, 2022
4b84f2b
Fix all the things!
karimodm Jun 27, 2022
86a8f41
Add bookEpoch test
daria305 Jun 27, 2022
05eeaf3
Fixes in tests
daria305 Jun 27, 2022
e12f721
Merge branch 'feat/epoch-commitment' into feat/add-epoch-committable-…
daria305 Jun 27, 2022
373e7ba
Fix Genesis snapshot loading with epoch 0
karimodm Jun 27, 2022
e6a1011
Use ATT time
daria305 Jun 27, 2022
ed908e8
Fix mManaVectorToUpdate event initialization
daria305 Jun 27, 2022
7b409cc
Remove --mana.snapshotResetTime=true from docker network compose
karimodm Jun 27, 2022
b5bffa0
Update packages/epoch/types.go
karimodm Jun 27, 2022
9e9180c
Address review
karimodm Jun 27, 2022
36b11ab
Merge branch 'test/notarization-manager' of github.com:iotaledger/gos…
karimodm Jun 27, 2022
233e79c
Update packages/notarization/manager.go
daria305 Jun 27, 2022
2fda38c
Apply review suggestions
daria305 Jun 28, 2022
04ba0c3
Merge remote-tracking branch 'origin/feat/add-epoch-committable-even'…
daria305 Jun 28, 2022
9e26820
Make diffs private
daria305 Jun 28, 2022
2287d1e
Fix: always check inclusionTime before triggering TransactionConfirme…
karimodm Jun 28, 2022
154172f
Remove unnecessary code
daria305 Jun 28, 2022
db3c51d
More fixes to bugs and tests
karimodm Jun 28, 2022
a482804
Merge branch 'test/notarization-manager' into feat/add-epoch-committa…
daria305 Jun 28, 2022
796e69e
Fix all tests
karimodm Jun 28, 2022
754b332
Remove prints
karimodm Jun 28, 2022
2ad8f30
Merge branch 'test/notarization-manager' into feat/add-epoch-committa…
daria305 Jun 28, 2022
16f0d20
Revert "Fix: always check inclusionTime before triggering Transaction…
karimodm Jun 28, 2022
b2562e1
Update commitments on new epoch event
daria305 Jun 28, 2022
34f35ee
txMeta.InclusionTime().IsZero() guard in OnTransactionConfirmed
karimodm Jun 28, 2022
3f387f9
Fix the indexes
daria305 Jun 28, 2022
1cce33e
Fix other unit tests
karimodm Jun 28, 2022
f9df532
Merge branch 'test/notarization-manager' into feat/add-epoch-committa…
daria305 Jun 29, 2022
04eae67
Fix TransactionConfirmed w/ InclusionTime
karimodm Jun 29, 2022
dd4e08d
Fix isCommittable condition, and race with ATT
daria305 Jun 29, 2022
4bee1c0
Fix most unit tests
daria305 Jun 29, 2022
ccc6ee9
Fix diff unittest
daria305 Jun 29, 2022
b73be48
Merge branch 'test/notarization-manager' into feat/add-epoch-committa…
daria305 Jun 29, 2022
dcafb04
Fix UpdateStateMutationTreeWithConflict unittest
daria305 Jun 29, 2022
23f559f
Trigger next epoch on AcceptanceTime updated
daria305 Jun 30, 2022
ba5e574
Advance epochs on ATT update: extend event to include ATT
karimodm Jun 30, 2022
d231efe
More unit test fixes
karimodm Jun 30, 2022
62c6c87
Remove check on Zero InclusionTime for Transactions
karimodm Jun 30, 2022
740ec58
Code quality
karimodm Jun 30, 2022
d09e326
Hook to ManaVectorUpdate from within mana plugin
karimodm Jun 30, 2022
10c517e
Fix BookEpoch test
daria305 Jun 30, 2022
8539312
Merge pull request #2311 from iotaledger/test/notarization-manager
karimodm Jun 30, 2022
0c2e82e
Code quality
karimodm Jun 30, 2022
c86e423
Fix TestPowFilter_Filter test
daria305 Jun 30, 2022
c16c509
Merge remote-tracking branch 'origin/feat/add-epoch-committable-even'…
daria305 Jun 30, 2022
14bd64d
Fix TestTangle_InvalidParentsAgeMessage
karimodm Jun 30, 2022
a56e061
Fix TestRateSetter_ErrorHandling test
daria305 Jun 30, 2022
e17ca9a
Merge remote-tracking branch 'origin/feat/add-epoch-committable-even'…
daria305 Jun 30, 2022
38cdc4e
Fix TestScheduler_SkipConfirmed test
daria305 Jun 30, 2022
f36e6b0
Fix TestScheduler_SkipConfirmed test
daria305 Jun 30, 2022
a21f832
Fix integration tests
karimodm Jun 30, 2022
1dd5ee0
Lock EpochCommittmentFactory upon OnAcceptanceTimeUpdated
karimodm Jun 30, 2022
a961773
ReadLock on GetLatestEC
karimodm Jun 30, 2022
264a437
Remove slow prints
karimodm Jun 30, 2022
63afe2c
Fresh GenesisTime
karimodm Jun 30, 2022
0a4a2d9
CMana calculation is now anchored to epochs
karimodm Jun 30, 2022
6ad7364
Fix: Set output pledgeID in booker
daria305 Jul 1, 2022
ff23c90
Merge remote-tracking branch 'origin/feat/add-epoch-committable-even'…
daria305 Jul 1, 2022
667f982
Fix: Set output pledgeID in booker
daria305 Jul 1, 2022
0edcfed
WIP mana tests
daria305 Jul 4, 2022
9dea252
Merge remote-tracking branch 'origin/feat/add-epoch-committable-even'…
daria305 Jul 4, 2022
5ef6ddb
Fix: Set output pledgeID in booker
daria305 Jul 1, 2022
f73b82d
Fix access mana pledge
daria305 Jul 4, 2022
e76f877
Fix invalid cast from MockedTransaction when storing outputs
karimodm Jul 4, 2022
8cc356d
Code quality
karimodm Jul 4, 2022
26655e3
Remove slow prints
karimodm Jul 4, 2022
c547a12
Introduce messageLayer.GenesisTime to reset genesis time on tests
karimodm Jul 4, 2022
981634d
Merge pull request #2312 from iotaledger/feat/add-epoch-committable-even
karimodm Jul 4, 2022
cdb316c
Fix: unused error
karimodm Jul 4, 2022
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
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ go 1.18

replace github.com/linxGnu/grocksdb => github.com/gohornet/grocksdb v1.6.34-0.20210518222204-d6ea5eedcfb9

replace github.com/lazyledger/smt => github.com/celestiaorg/smt v0.2.1-0.20220414134126-dba215ccb884

require (
github.com/AlecAivazis/survey/v2 v2.3.4
github.com/ReneKroon/ttlcache/v2 v2.11.0
Expand All @@ -18,6 +20,7 @@ require (
github.com/iotaledger/hive.go v0.0.0-20220323102937-0cf57aabb23a
github.com/labstack/echo v3.3.10+incompatible
github.com/labstack/gommon v0.3.0
github.com/lazyledger/smt v0.2.0
github.com/libp2p/go-libp2p v0.15.0
github.com/libp2p/go-libp2p-core v0.9.0
github.com/libp2p/go-yamux/v2 v2.2.0
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ github.com/buger/jsonparser v0.0.0-20181115193947-bf1c66bbce23/go.mod h1:bbYlZJ7
github.com/capossele/asset-registry v0.0.0-20210521112927-c9d6e74574e8 h1:lCaU8zjlV8f06WK3jlruYmTUPVumZ4sxj0CEyg/k0IU=
github.com/capossele/asset-registry v0.0.0-20210521112927-c9d6e74574e8/go.mod h1:BXwVCA0+rgYcMKC3vVkfjF+2nXYIYq3h/HndbaCuw08=
github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ=
github.com/celestiaorg/smt v0.2.1-0.20220414134126-dba215ccb884 h1:iRNKw2WmAbVgGMNYzDH5Y2yY3+jyxwEK9Hc5pwIjZAE=
github.com/celestiaorg/smt v0.2.1-0.20220414134126-dba215ccb884/go.mod h1:/sdYDakowo/XaxS2Fl7CBqtuf/O2uTqF2zmAUFAtAiw=
github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM=
github.com/cenkalti/backoff/v4 v4.1.1/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
Expand Down Expand Up @@ -681,6 +683,8 @@ github.com/labstack/echo v3.3.10+incompatible/go.mod h1:0INS7j/VjnFxD4E2wkz67b8c
github.com/labstack/echo/v4 v4.1.11/go.mod h1:i541M3Fj6f76NZtHSj7TXnyM8n2gaodfvfxNnFqi74g=
github.com/labstack/gommon v0.3.0 h1:JEeO0bvc78PKdyHxloTKiF8BD5iGrH8T6MSeGvSgob0=
github.com/labstack/gommon v0.3.0/go.mod h1:MULnywXg0yavhxWKc+lOruYdAhDwPK9wf0OL7NoOu+k=
github.com/lazyledger/smt v0.2.0 h1:0Y64tz0kP5MJrpaO5nTYDLtBidkh6LDi8snGozlYwFU=
github.com/lazyledger/smt v0.2.0/go.mod h1:9+Pb2/tg1PvEgW7aFx4bFhDE4bvbI03zuJ8kb7nJ9Jc=
github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y=
github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
github.com/libp2p/go-addr-util v0.0.1/go.mod h1:4ac6O7n9rIAKB1dnd+s8IbbMXkt+oBpzX4/+RACcnlQ=
Expand Down
1 change: 1 addition & 0 deletions packages/consensus/finality/finality_gadget.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ func NewSimpleFinalityGadget(t *tangle.Tangle, opts ...Option) *SimpleFinalityGa
MessageConfirmed: events.NewEvent(tangle.MessageIDCaller),
TransactionConfirmed: events.NewEvent(ledgerstate.TransactionIDEventHandler),
BranchConfirmed: events.NewEvent(ledgerstate.BranchIDEventHandler),
BranchRejected: events.NewEvent(ledgerstate.BranchIDEventHandler),
TransactionGoFChanged: events.NewEvent(ledgerstate.TransactionIDEventHandler),
BranchGoFChanged: events.NewEvent(BranchIDGoFEventHandler),
},
Expand Down
7 changes: 4 additions & 3 deletions packages/ledgerstate/branch_dag.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func (b *BranchDAG) ResolvePendingBranchIDs(branchIDs BranchIDs) (pendingBranchI
}

// SetBranchConfirmed sets the InclusionState of the given Branch to be Confirmed.
func (b *BranchDAG) SetBranchConfirmed(branchID BranchID) (modified bool) {
func (b *BranchDAG) SetBranchConfirmed(branchID BranchID) (modified bool, rejectedBranches BranchIDs) {
b.inclusionStateMutex.Lock()
defer b.inclusionStateMutex.Unlock()

Expand Down Expand Up @@ -193,19 +193,20 @@ func (b *BranchDAG) SetBranchConfirmed(branchID BranchID) (modified bool) {
})
}

rejectedBranches = NewBranchIDs()
for rejectedWalker.HasNext() {
b.Branch(rejectedWalker.Next()).Consume(func(branch *Branch) {
if modified = branch.setInclusionState(Rejected); !modified {
return
}

rejectedBranches.Add(branch.ID())
b.ChildBranches(branch.ID()).Consume(func(childBranch *ChildBranch) {
rejectedWalker.Push(childBranch.ChildBranchID())
})
})
}

return modified
return modified, rejectedBranches
}

// InclusionState returns the InclusionState of the given BranchIDs.
Expand Down
6 changes: 4 additions & 2 deletions packages/ledgerstate/branch_dag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ func TestBranchDAG_SetBranchConfirmed(t *testing.T) {
branchIDs["Branch7"] = createBranch(t, ledgerstate, "Branch7", NewBranchIDs(MasterBranchID), NewConflictIDs(ConflictID{2}))
branchIDs["Branch8"] = createBranch(t, ledgerstate, "Branch8", NewBranchIDs(MasterBranchID), NewConflictIDs(ConflictID{2}))

assert.True(t, ledgerstate.BranchDAG.SetBranchConfirmed(branchIDs["Branch4"]))
modified, _ := ledgerstate.BranchDAG.SetBranchConfirmed(branchIDs["Branch4"])
assert.True(t, modified)

assertInclusionStates(t, ledgerstate, branchIDs, map[string]InclusionState{
"Branch2": Confirmed,
Expand All @@ -132,7 +133,8 @@ func TestBranchDAG_SetBranchConfirmed(t *testing.T) {
"Branch5+Branch8": Rejected,
})

assert.True(t, ledgerstate.BranchDAG.SetBranchConfirmed(branchIDs["Branch8"]))
modified, _ = ledgerstate.BranchDAG.SetBranchConfirmed(branchIDs["Branch8"])
assert.True(t, modified)

// Create a new Branch in an already-decided Conflict set results in straight Reject
branchIDs["Branch9"] = createBranch(t, ledgerstate, "Branch9", NewBranchIDs(MasterBranchID), NewConflictIDs(ConflictID{2}))
Expand Down
10 changes: 6 additions & 4 deletions packages/ledgerstate/ledgerstate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ func TestLedgerstate_SetBranchConfirmed(t *testing.T) {

// Mark A as Confirmed
{
require.True(t, ledgerstate.BranchDAG.SetBranchConfirmed(getSingleBranch(branches, "A")))
modified, _ := ledgerstate.BranchDAG.SetBranchConfirmed(getSingleBranch(branches, "A"))
require.True(t, modified)

assertBranchIDs(t, ledgerstate, transactions["A"], branches["A"])
assertBranchIDs(t, ledgerstate, transactions["B"], branches["B"])
Expand Down Expand Up @@ -93,7 +94,8 @@ func TestLedgerstate_SetBranchConfirmed(t *testing.T) {
})
}

require.True(t, ledgerstate.BranchDAG.SetBranchConfirmed(getSingleBranch(branches, "D")))
modified, _ := ledgerstate.BranchDAG.SetBranchConfirmed(getSingleBranch(branches, "D"))
require.True(t, modified)

setupScenarioTopTopLayer(t, wallets, outputs, ledgerstate, inputs, manaPledgeID, transactions, branches)

Expand All @@ -118,8 +120,8 @@ func TestLedgerstate_SetBranchConfirmed(t *testing.T) {
assert.Equal(t, Pending, ledgerstate.BranchDAG.InclusionState(branches["H"]))
assert.Equal(t, Pending, ledgerstate.BranchDAG.InclusionState(branches["I"]))
}

require.True(t, ledgerstate.BranchDAG.SetBranchConfirmed(getSingleBranch(branches, "H")))
modified, _ = ledgerstate.BranchDAG.SetBranchConfirmed(getSingleBranch(branches, "H"))
require.True(t, modified)

setupScenarioTopTopTopLayer(t, wallets, outputs, ledgerstate, inputs, manaPledgeID, transactions)

Expand Down
222 changes: 222 additions & 0 deletions packages/notarization/commitments.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
package notarization

import (
"sync"

"github.com/lazyledger/smt"
"golang.org/x/crypto/blake2b"

"github.com/iotaledger/goshimmer/packages/database"
"github.com/iotaledger/goshimmer/packages/ledgerstate"
"github.com/iotaledger/goshimmer/packages/tangle"
"github.com/iotaledger/hive.go/marshalutil"
)

var (
prevTangleRootKey = []byte("previousTangleRoot")
prevStateMutationRootKey = []byte("prevStateMutationRootKey")
prevECR = []byte("previousEpochCommitmentRoot")
)

// EpochCommitment contains the ECR and prevECR of an epoch.
type EpochCommitment struct {
EI EI
EC []byte
}

// Commitment is a compressed form of all the information (messages and confirmed value payloads) of an epoch.
type Commitment struct {
EI EI
tangleRoot *smt.SparseMerkleTree
stateMutationRoot *smt.SparseMerkleTree
stateRoot *smt.SparseMerkleTree
prevECR []byte
}

// NewCommitment returns an empty commitment for the epoch.
func NewCommitment(ei EI, prevECR, prevMessageRoot, prevTransactionRoot []byte) *Commitment {
db, _ := database.NewMemDB()
messageIDStore := db.NewStore()
messageValueStore := db.NewStore()
stateIDStore := db.NewStore()
stateValueStore := db.NewStore()
stateMutationIDStore := db.NewStore()
stateMutationValueStore := db.NewStore()

hasher, _ := blake2b.New256(nil)
commitment := &Commitment{
EI: ei,
tangleRoot: smt.NewSparseMerkleTree(messageIDStore, messageValueStore, hasher),
stateMutationRoot: smt.NewSparseMerkleTree(stateIDStore, stateValueStore, hasher),
stateRoot: smt.NewSparseMerkleTree(stateMutationIDStore, stateMutationValueStore, hasher),
prevECR: prevECR,
}

commitment.tangleRoot.Update(prevTangleRootKey, prevMessageRoot)
commitment.stateMutationRoot.Update(prevStateMutationRootKey, prevTransactionRoot)
acha-bill marked this conversation as resolved.
Show resolved Hide resolved
return commitment
}

// TangleRoot returns the root of the tangle sparse merkle tree.
func (e *Commitment) TangleRoot() []byte {
return e.tangleRoot.Root()
}

// StateMutationRoot returns the root of the state mutation sparse merkle tree.
func (e *Commitment) StateMutationRoot() []byte {
return e.stateMutationRoot.Root()
}

// StateRoot returns the root of the state sparse merkle tree.
func (e *Commitment) StateRoot() []byte {
return e.stateRoot.Root()
}

// ECR generates the epoch commitment root.
func (e *Commitment) ECR() []byte {
branch1 := blake2b.Sum256(append(e.prevECR, e.TangleRoot()...))
branch2 := blake2b.Sum256(append(e.StateRoot(), e.StateMutationRoot()...))
var root []byte
root = append(root, branch1[:]...)
root = append(root, branch2[:]...)
ecr := blake2b.Sum256(root)

return ecr[:]
}

// EpochCommitmentFactory manages epoch commitments.
type EpochCommitmentFactory struct {
commitments map[EI]*Commitment
commitmentsMutex sync.RWMutex
}

// NewEpochCommitmentFactory returns a new commitment factory.
func NewEpochCommitmentFactory() *EpochCommitmentFactory {
return &EpochCommitmentFactory{
commitments: make(map[EI]*Commitment),
}
}

// InsertTangleLeaf inserts msg to the Tangle sparse merkle tree.
func (f *EpochCommitmentFactory) InsertTangleLeaf(ei EI, msgID tangle.MessageID) {
commitment := f.getOrCreateCommitment(ei)
commitment.tangleRoot.Update(msgID.Bytes(), msgID.Bytes())
f.onTangleRootChanged(commitment)
}

// InsertStateLeaf inserts the outputID to the state sparse merkle tree.
func (f *EpochCommitmentFactory) InsertStateLeaf(ei EI, outputID ledgerstate.OutputID) {
commitment := f.getOrCreateCommitment(ei)
commitment.stateRoot.Update(outputID.Bytes(), outputID.Bytes())
f.onStateRootChanged(commitment)
}

// InsertStateMutationLeaf inserts the transaction ID to the state mutation sparse merkle tree.
func (f *EpochCommitmentFactory) InsertStateMutationLeaf(ei EI, txID ledgerstate.TransactionID) {
commitment := f.getOrCreateCommitment(ei)
commitment.stateMutationRoot.Update(txID.Bytes(), txID.Bytes())
f.onStateMutationRootChanged(commitment)
}

// RemoveTangleLeaf removes the message ID from the Tangle sparse merkle tree.
func (f *EpochCommitmentFactory) RemoveTangleLeaf(ei EI, msgID tangle.MessageID) {
commitment := f.getOrCreateCommitment(ei)
exists, _ := commitment.stateRoot.Has(msgID.Bytes())
if exists {
commitment.tangleRoot.Delete(msgID.Bytes())
f.onTangleRootChanged(commitment)
}
}

// RemoveStateLeaf removes the output ID from the ledgerstate sparse merkle tree.
func (f *EpochCommitmentFactory) RemoveStateLeaf(ei EI, outID ledgerstate.OutputID) {
commitment := f.getOrCreateCommitment(ei)
exists, _ := commitment.stateRoot.Has(outID.Bytes())
if exists {
commitment.stateRoot.Delete(outID.Bytes())
f.onStateRootChanged(commitment)
}
}

// GetCommitment returns the commitment with the given ei.
func (f *EpochCommitmentFactory) GetCommitment(ei EI) *Commitment {
f.commitmentsMutex.RLock()
defer f.commitmentsMutex.RUnlock()
return f.commitments[ei]
}

// GetEpochCommitment returns the epoch commitment with the given ei.
func (f *EpochCommitmentFactory) GetEpochCommitment(ei EI) *EpochCommitment {
f.commitmentsMutex.RLock()
defer f.commitmentsMutex.RUnlock()
if commitment, ok := f.commitments[ei]; ok {
marshalUtil := marshalutil.New()

marshalUtil.WriteBytes(commitment.prevECR)
marshalUtil.WriteBytes(commitment.ECR())
marshalUtil.WriteInt64(int64(ei))
ec := blake2b.Sum256(marshalUtil.Bytes())

return &EpochCommitment{
EI: ei,
EC: ec[:],
}
}
return nil
}

func (f *EpochCommitmentFactory) getOrCreateCommitment(ei EI) *Commitment {
f.commitmentsMutex.RLock()
commitment, ok := f.commitments[ei]
f.commitmentsMutex.RUnlock()
if !ok {
var previousMessageRoot []byte
var previousTransactionRoot, previousECR []byte

if ei > 0 {
if previousCommitment := f.GetCommitment(ei - 1); previousCommitment != nil {
previousMessageRoot = previousCommitment.TangleRoot()
previousTransactionRoot = previousCommitment.StateMutationRoot()
previousECR = previousCommitment.ECR()
}
}
commitment = NewCommitment(ei, previousECR, previousMessageRoot, previousTransactionRoot)
f.commitmentsMutex.Lock()
f.commitments[ei] = commitment
f.commitmentsMutex.Unlock()
}
return commitment
}

func (f *EpochCommitmentFactory) onTangleRootChanged(commitment *Commitment) {
f.commitmentsMutex.RLock()
defer f.commitmentsMutex.RUnlock()
forwardCommitment, ok := f.commitments[commitment.EI+1]
if !ok {
return
}
forwardCommitment.tangleRoot.Update(prevTangleRootKey, commitment.TangleRoot())
forwardCommitment.prevECR = commitment.ECR()
}

func (f *EpochCommitmentFactory) onStateMutationRootChanged(commitment *Commitment) {
f.commitmentsMutex.RLock()
defer f.commitmentsMutex.RUnlock()
forwardCommitment, ok := f.commitments[commitment.EI+1]
if !ok {
return
}
forwardCommitment.stateMutationRoot.Update(prevStateMutationRootKey, commitment.StateMutationRoot())
forwardCommitment.prevECR = commitment.ECR()
}

func (f *EpochCommitmentFactory) onStateRootChanged(commitment *Commitment) {
f.commitmentsMutex.RLock()
defer f.commitmentsMutex.RUnlock()
forwardCommitment, ok := f.commitments[commitment.EI+1]
if !ok {
return
}
forwardCommitment.stateRoot.Update(prevStateMutationRootKey, commitment.StateMutationRoot())
forwardCommitment.prevECR = commitment.ECR()
}
Loading