Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
firelizzard18 committed Dec 13, 2024
1 parent ccb8ead commit a89c84c
Showing 1 changed file with 8 additions and 37 deletions.
45 changes: 8 additions & 37 deletions tools/cmd/debug/heal_synth.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ func healSynth(cmd *cobra.Command, args []string) {
// Pull chains
pullSynthDirChains(h)
pullSynthSrcChains(h, srcUrl)
pullSynthDstChains(h, dstUrl)

// Pull accounts
pullSynthLedger(h, srcUrl)
Expand All @@ -61,7 +60,6 @@ func healSynth(cmd *cobra.Command, args []string) {
// Pull chains
pullSynthDirChains(h)
pullSynthSrcChains(h, srcUrl)
pullSynthDstChains(h, dstUrl)

// Pull accounts
pullAgain:
Expand Down Expand Up @@ -136,7 +134,7 @@ func pullSynthDirChains(h *healer) {

check(h.light.PullAccount(ctx, protocol.DnUrl().JoinPath(protocol.Network)))

check(h.light.PullAccountWithChains(ctx, protocol.DnUrl().JoinPath(protocol.Ledger), include("root").and("root-index")))
check(h.light.PullAccountWithChains(ctx, protocol.DnUrl().JoinPath(protocol.Ledger), includeRootChain))
check(h.light.IndexAccountChains(ctx, protocol.DnUrl().JoinPath(protocol.Ledger)))

check(h.light.PullAccountWithChains(ctx, protocol.DnUrl().JoinPath(protocol.AnchorPool), func(c *api.ChainRecord) bool {
Expand All @@ -149,7 +147,7 @@ func pullSynthSrcChains(h *healer, part *url.URL) {
ctx, cancel, _ := api.ContextWithBatchData(h.ctx)
defer cancel()

check(h.light.PullAccountWithChains(ctx, part.JoinPath(protocol.Ledger), include("root").and("root-index")))
check(h.light.PullAccountWithChains(ctx, part.JoinPath(protocol.Ledger), includeRootChain))
check(h.light.IndexAccountChains(ctx, part.JoinPath(protocol.Ledger)))

check(h.light.PullAccountWithChains(ctx, part.JoinPath(protocol.Synthetic), func(c *api.ChainRecord) bool {
Expand All @@ -158,25 +156,8 @@ func pullSynthSrcChains(h *healer, part *url.URL) {
check(h.light.IndexAccountChains(ctx, part.JoinPath(protocol.Synthetic)))
}

func pullSynthDstChains(h *healer, part *url.URL) {
// ctx, cancel, _ := api.ContextWithBatchData(h.ctx)
// defer cancel()

// check(h.light.PullAccountWithChains(ctx, part.JoinPath(protocol.Ledger), include("root").and("root-index")))
// check(h.light.IndexAccountChains(ctx, part.JoinPath(protocol.Ledger)))
// check(h.light.PullAccountWithChains(ctx, part.JoinPath(protocol.AnchorPool), skipSigChain))
// check(h.light.IndexAccountChains(ctx, part.JoinPath(protocol.AnchorPool)))

// if healSinceDuration > 0 {
// check(h.light.PullMessagesForAccountSince(ctx, part.JoinPath(protocol.AnchorPool), time.Now().Add(-healSinceDuration), "main"))
// } else {
// check(h.light.PullMessagesForAccount(ctx, part.JoinPath(protocol.AnchorPool), "main"))
// }
// check(h.light.IndexReceivedAnchors(ctx, part))
}

func pullSynthLedger(h *healer, part *url.URL) *protocol.SyntheticLedger {
check(h.light.PullAccountWithChains(h.ctx, part.JoinPath(protocol.Synthetic), skipAllChains))
check(h.light.PullAccountWithChains(h.ctx, part.JoinPath(protocol.Synthetic), func(cr *api.ChainRecord) bool { return false }))

batch := h.light.OpenDB(false)
defer batch.Discard()
Expand All @@ -186,24 +167,14 @@ func pullSynthLedger(h *healer, part *url.URL) *protocol.SyntheticLedger {
return ledger
}

func skipSigChain(c *api.ChainRecord) bool {
return c.Name != "signature"
}

func skipAllChains(*api.ChainRecord) bool {
return false
}

type chainFilter func(*api.ChainRecord) bool

func include(name string) chainFilter { return chainFilter(nil).and(name) }

func (f chainFilter) and(name string) chainFilter {
g := func(c *api.ChainRecord) bool {
return c.Name == name
}
if f == nil {
return g
func includeRootChain(c *api.ChainRecord) bool {
switch c.Name {
case "root", "root-index":
return true
}
return func(c *api.ChainRecord) bool { return f(c) || g(c) }
return false
}

0 comments on commit a89c84c

Please sign in to comment.