Skip to content

Commit

Permalink
Start node from live snapshot (iotaledger#2618)
Browse files Browse the repository at this point in the history
* Snapshot creation and loading

* Bind /slot/:index to dashboard explorer routes

* Do not set chainID in the settings to latest commitment of settings. This lead to an issue where a newly joining always sets its chain ID based on whatever it reads from an obtained snapshot

* Clean up prints

* Remove debug prints

* More debug prints for node startup with existing DB

* Forking point of initialized chain should always be Genesis

* works

* still works..

* Amend join_network.sh

* Make chainManager commits evictable

* WIP: start with ChainManager's rootCommitment

* Git to ignore docker network dynamic snapshot

* Evaluate against chain rootCommitment

* Fix unit tests

* Fixes and some unit tests

* rootCommit needs to be on a valid chain

* Comment fix

* Simplify methods

* Add unit tests for processing root commitment

* WIP

* Set rootCommitment on eviction

* WIP

* Extend test with eviction and add check for root commitment when retrieving commitment

* Introduce CommitmentBelowRoot event and fix unit tests

* More detailed prints

* Set root commitment only after engine is initialized (and thus snapshot loaded) and more detailed prints

* Set main Engine chain to snapshot commitment

* Store commitments along rootblocks to set chainID from snapshot

* DEBUG: remove prints

* Enable WebAPISnapshot when deploying

* Fix some unit tests

* Fix chain forking test

* Please doggo

* Proper lock ChainManager's evictionMutex from exported methods

* Remove TODO: we set chainID from snapshot even on forking

* Do not double-lock on detecting forks

* Address review comments

* Added comments and root commitment check when setting

* Test root blocks and chain ids

* WIP test

* Unit test for rootBlocks and chainID from snapshot

* Address review

---------

Co-authored-by: jonastheis <[email protected]>
  • Loading branch information
karimodm and jonastheis authored Mar 23, 2023
1 parent 807261d commit d8e651d
Show file tree
Hide file tree
Showing 26 changed files with 844 additions and 293 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,6 @@ config.json
.env
.vscode

# dynamic docker-network snapshot
tools/docker-network/docker-network.snapshot

Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ services:
--autoPeering.networkVersion={{ networkVersion }}
{% endif %}
--node.disablePlugins=portcheck,ManaInitializer{% if remoteLogs|default(false) == false %},RemoteLog,RemoteLogMetrics{% endif %}
--node.enablePlugins=dashboard,metrics{% if faucet|default(false) %},faucet,WebAPIFaucetEndpoint{% endif %},activity,snapshot,WebAPIToolsBlockEndpoint,"WebAPI tools Endpoint"{% if spammer|default(false) %},spammer{% endif %}{% if remoteLogs|default(false) %},RemoteLog,RemoteLogMetrics{% endif %},profilingrecorder
--node.enablePlugins=dashboard,metrics{% if faucet|default(false) %},faucet,WebAPIFaucetEndpoint{% endif %},activity,WebAPISnapshot,WebAPIToolsBlockEndpoint,"WebAPI tools Endpoint"{% if spammer|default(false) %},spammer{% endif %}{% if remoteLogs|default(false) %},RemoteLog,RemoteLogMetrics{% endif %},profilingrecorder
--metrics.bindAddress=0.0.0.0:9311
--activity.broadcastInterval=1s
{% if faucet|default(false) %}
Expand Down
5 changes: 5 additions & 0 deletions packages/app/jsonmodels/webapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,3 +253,8 @@ type GetUnspentOutputResponse struct {
}

// endregion ///////////////////////////////////////////////////////////////////////////////////////////////////////////

// GetSnapshotRequest represents the JSON model of a GetSnapshot request.
type GetSnapshotRequest struct {
SlotIndex uint64 `query:"index"`
}
5 changes: 5 additions & 0 deletions packages/core/commitment/commitment.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,8 @@ func (c *Commitment) RootsID() (rootsID types.Identifier) {
func (c *Commitment) CumulativeWeight() (cumulativeWeight int64) {
return c.M.CumulativeWeight
}

func (c *Commitment) Equals(other *Commitment) bool {
return c.ID() == other.ID() && c.PrevID() == other.PrevID() && c.Index() == other.Index() &&
c.RootsID() == other.RootsID() && c.CumulativeWeight() == other.CumulativeWeight()
}
2 changes: 2 additions & 0 deletions packages/protocol/chainmanager/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
type Events struct {
CommitmentMissing *event.Event1[commitment.ID]
MissingCommitmentReceived *event.Event1[commitment.ID]
CommitmentBelowRoot *event.Event1[commitment.ID]
ForkDetected *event.Event1[*Fork]
EvictionState *eviction.Events

Expand All @@ -19,6 +20,7 @@ var NewEvents = event.CreateGroupConstructor(func() *Events {
return &Events{
CommitmentMissing: event.New1[commitment.ID](),
MissingCommitmentReceived: event.New1[commitment.ID](),
CommitmentBelowRoot: event.New1[commitment.ID](),
ForkDetected: event.New1[*Fork](),
}
})
Loading

0 comments on commit d8e651d

Please sign in to comment.