Skip to content

Commit

Permalink
Improve anchor healing [#3379]
Browse files Browse the repository at this point in the history
  • Loading branch information
firelizzard18 committed Oct 15, 2023
1 parent 2e84f24 commit c1cab75
Show file tree
Hide file tree
Showing 29 changed files with 2,203 additions and 605 deletions.
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
*.exe
.git
*/Dockerfile
.test
.test
27 changes: 24 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -539,11 +539,14 @@
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/tools/cmd/resend-anchor",
"program": "${workspaceFolder}/tools/cmd/debug",
"cwd": "${workspaceFolder}",
"args": [
"heal",
"https://mainnet.accumulatenetwork.io/v3",
"anchor",
"MainNet",
"--cached-scan=${env:HOME}/.accumulate/cache/mainnet.json",
"Directory→Apollo", "70911"
]
},
{
Expand All @@ -557,9 +560,27 @@
"program": "${workspaceFolder}/tools/cmd/debug",
"cwd": "${workspaceFolder}",
"args": [
"heal-synth",
"heal",
"synth",
"mainnet",
"--cached-scan=${env:HOME}/.accumulate/cache/mainnet.json",
]
},
{
"name": "Heal single anchor",
"presentation": { "group": "99-Miscellaneous", },
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/tools/cmd/debug",
"cwd": "${workspaceFolder}",
"args": [
"heal",
"anchor",
"mainnet",
"Chandrayaan → Apollo",
// "acc://f18b9ddd70654849ce063581b7bcbc6947d4b763d7a2fa4668e6fd9129da0e23@dn.acme/anchors",
"--cached-scan=${env:HOME}/.accumulate/cache/mainnet.json",
]
},
{
Expand Down
43 changes: 3 additions & 40 deletions cmd/accumulated-http/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,12 @@ import (
"github.com/multiformats/go-multiaddr"
"github.com/rs/cors"
"github.com/spf13/cobra"
"gitlab.com/accumulatenetwork/accumulate/internal/api/routing"
"gitlab.com/accumulatenetwork/accumulate/exp/apiutil"
accumulated "gitlab.com/accumulatenetwork/accumulate/internal/node/daemon"
nodehttp "gitlab.com/accumulatenetwork/accumulate/internal/node/http"
. "gitlab.com/accumulatenetwork/accumulate/internal/util/cmd"
"gitlab.com/accumulatenetwork/accumulate/pkg/accumulate"
"gitlab.com/accumulatenetwork/accumulate/pkg/api/v3"
"gitlab.com/accumulatenetwork/accumulate/pkg/api/v3/message"
"gitlab.com/accumulatenetwork/accumulate/pkg/api/v3/p2p"
"gitlab.com/accumulatenetwork/accumulate/pkg/api/v3/p2p/dial"
"gitlab.com/accumulatenetwork/accumulate/protocol"
"golang.org/x/crypto/acme/autocert"
"golang.org/x/exp/slog"
)
Expand Down Expand Up @@ -126,46 +122,13 @@ func run(_ *cobra.Command, args []string) {

fmt.Printf("We are %v\n", node.ID())

dirNetSvc := api.ServiceTypeNetwork.AddressFor(protocol.Directory)
tr, ok := node.Tracker().(*dial.PersistentTracker)
if !ok {
fmt.Println("Waiting for a live network service")
svcAddr, err := dirNetSvc.MultiaddrFor(args[0])
Check(err)
Check(node.WaitForService(ctx, svcAddr))

} else {
var found bool
for _, peer := range tr.DB().Peers.Load() {
if peer.Network(args[0]).Service(dirNetSvc).Last.Success != nil {
found = true
}
}

if !found {
fmt.Println("Scanning for peers")
tr.ScanPeers(5 * time.Minute)
}
}

fmt.Println("Fetching routing information")
router := new(routing.MessageRouter)
client := &message.Client{
Transport: &message.RoutedTransport{
Network: args[0],
Dialer: node.DialNetwork(),
Router: router,
},
}
ns, err := client.NetworkStatus(ctx, api.NetworkStatusOptions{})
Check(err)
router.Router, err = routing.NewStaticRouter(ns.Routing, logger)
router, err := apiutil.InitRouter(ctx, node, args[0])
Check(err)

api, err := nodehttp.NewHandler(nodehttp.Options{
Logger: logger,
Node: node,
Router: router.Router,
Router: router,
MaxWait: 10 * time.Second,
NetworkId: args[0],
})
Expand Down
58 changes: 58 additions & 0 deletions exp/apiutil/mainnet.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright 2023 The Accumulate Authors
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.

package apiutil

import "github.com/multiformats/go-multiaddr"

var MainnetAddrs = func() []multiaddr.Multiaddr {
s := []string{
"/dns/apollo-mainnet.accumulate.defidevs.io/tcp/16593/p2p/12D3KooWAgrBYpWEXRViTnToNmpCoC3dvHdmR6m1FmyKjDn1NYpj",
"/dns/yutu-mainnet.accumulate.defidevs.io/tcp/16593/p2p/12D3KooWDqFDwjHEog1bNbxai2dKSaR1aFvq2LAZ2jivSohgoSc7",
"/dns/chandrayaan-mainnet.accumulate.defidevs.io/tcp/16593/p2p/12D3KooWHzjkoeAqe7L55tAaepCbMbhvNu9v52ayZNVQobdEE1RL",
"/ip4/116.202.214.38/tcp/16593/p2p/12D3KooWBkJQiuvotpMemWBYfAe4ctsVHi7fLvT8RT83oXJ5dsgV",
"/ip4/83.97.19.82/tcp/16593/p2p/12D3KooWHSbqS6K52d4ReauHAg4n8MFbAKkdEAae2fZXnzRYi9ce",
"/ip4/206.189.97.165/tcp/16593/p2p/12D3KooWHyA7zgAVqGvCBBJejgvKzv7DQZ3LabJMWqmCQ9wFbT3o",
"/ip4/144.76.105.23/tcp/16593/p2p/12D3KooWS2Adojqun5RV1Xy4k6vKXWpRQ3VdzXnW8SbW7ERzqKie",
"/ip4/18.190.77.236/tcp/16593/p2p/12D3KooWP1d9vUJCzqX5bTv13tCHmVssJrgK3EnJCC2C5Ep2SXbS",
"/ip4/3.28.207.55/tcp/16593/p2p/12D3KooWEzhg3CRvC3xdrUBFsWETF1nG3gyYfEjx4oEJer95y1Rk",
"/ip4/38.135.195.81/tcp/16593/p2p/12D3KooWDWCHGAyeUWdP8yuuSYvMoUfaPoGu4p3gJb51diqNQz6j",
// "/ip4/50.17.246.3/tcp/16593/p2p/12D3KooWKkNsxkHJqvSje2viyqKVxtqvbTpFrbASD3q1uv6td1pW",
"/dns/validator-eu01.acme.sphereon.com/tcp/16593/p2p/12D3KooWKYTWKJ5jeuZmbbwiN7PoinJ2yJLoQtZyfWi2ihjBnSUR",
"/ip4/35.86.120.53/tcp/16593/p2p/12D3KooWKJuspMDC5GXzLYJs9nHwYfqst9QAW4m5FakXNHVMNiq7",
"/ip4/65.109.48.173/tcp/16593/p2p/12D3KooWHkUtGcHY96bNavZMCP2k5ps5mC7GrF1hBC1CsyGJZSPY",
"/dns/accumulate.detroitledger.tech/tcp/16593/p2p/12D3KooWNe1QNh5mKAa8iAEP8vFwvmWFxaCLNcAdE1sH38Bz8sc9",
"/ip4/3.135.9.97/tcp/16593/p2p/12D3KooWEQG3X528Ct2Kd3kxhv6WZDBqaAoEw7AKiPoK1NmWJgx1",
// "/ip4/3.86.85.133/tcp/16593/p2p/12D3KooWJvReA1SuLkppyXKXq6fifVPLqvNtzsvPUqagVjvYe7qe",
"/ip4/193.35.56.176/tcp/16593/p2p/12D3KooWJevZUFLqN7zAamDh2EEYNQZPvxGFwiFVyPXfuXZNjg1J",
"/ip4/35.177.70.195/tcp/16593/p2p/12D3KooWPzpRp1UCu4nvXT9h8jKvmBmCADrMnoF72DrEbUrWrB2G",
"/ip4/3.99.81.122/tcp/16593/p2p/12D3KooWLL5kAbD7nhv6CM9x9L1zjxSnc6hdMVKcsK9wzMGBo99X",
"/ip4/34.219.75.234/tcp/16593/p2p/12D3KooWKHjS5nzG9dipBXn31pYEnfa8g5UzvkSYEsuiukGHzPvt",
"/ip4/3.122.254.53/tcp/16593/p2p/12D3KooWRU8obVzgfw6TsUHjoy2FDD3Vd7swrPNTM7DMFs8JG4dx",
"/ip4/35.92.228.236/tcp/16593/p2p/12D3KooWQqMqbyJ2Zay9KHeEDgDMAxQpKD1ypiBX5ByQAA2XpsZL",
"/ip4/3.135.184.194/tcp/16593/p2p/12D3KooWHcxyiE3AGdPnhtj87tByfLnJZVR6mLefadWccbMByrBa",
"/ip4/18.133.170.113/tcp/16593/p2p/12D3KooWFbWY2NhBEWTLHUCwwPmNHm4BoJXbojnrJJfuDCVoqrFY",
// "/ip4/44.204.224.126/tcp/16593/p2p/12D3KooWAiJJxdgsB39up5h6fz6TSfBz4HsLKTFiBXUrbwA8o54m",
"/ip4/35.92.21.90/tcp/16593/p2p/12D3KooWLTV3pTN2NbKeFeseCGHyMXuAkQv68KfCeK4uqJzJMfhZ",
"/ip4/3.99.166.147/tcp/16593/p2p/12D3KooWGYUf93iYWsUibSvKdxsYUY1p7fC1nQotCpUcDXD1ABvR",
"/ip4/16.171.4.135/tcp/16593/p2p/12D3KooWEMpAxKnXJPkcEXpDmrnjrZ5iFMZvvQtimmTTxuoRGkXV",
"/ip4/54.237.244.42/tcp/16593/p2p/12D3KooWLoMkrgW862Gs152jLt6FiZZs4GkY24Su4QojnvMoSNaQ",
// "/ip4/3.238.124.43/tcp/16593/p2p/12D3KooWJ8CA8pacTnKWVgBSEav4QG1zJpyeSSME47RugpDUrZp8",
"/ip4/13.53.125.115/tcp/16593/p2p/12D3KooWBJk52fQExXHWhFNk692hP7JvTxNTvUMdVne8tbJ3DBf3",
"/ip4/13.59.241.224/tcp/16593/p2p/12D3KooWKjYKqg2TgUSLq8CZAP8G6LhjXUWTcQBd9qYL2JHug9HW",
"/ip4/18.168.202.86/tcp/16593/p2p/12D3KooWDiKGbUZg1rB5EufRCkRPiDCEPMjyvTfTVR9qsKVVkcuC",
"/ip4/35.183.112.161/tcp/16593/p2p/12D3KooWFPKeXzKMd3jtoeG6ts6ADKmVV8rVkXR9k9YkQPgpLzd6",
}
addrs := make([]multiaddr.Multiaddr, len(s))
for i, s := range s {
addr, err := multiaddr.NewMultiaddr(s)
if err != nil {
panic(err)
}
addrs[i] = addr
}
return addrs
}()
77 changes: 77 additions & 0 deletions exp/apiutil/p2p.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Copyright 2023 The Accumulate Authors
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.

package apiutil

import (
"context"
"fmt"
"time"

"gitlab.com/accumulatenetwork/accumulate/internal/api/routing"
"gitlab.com/accumulatenetwork/accumulate/pkg/api/v3"
"gitlab.com/accumulatenetwork/accumulate/pkg/api/v3/message"
"gitlab.com/accumulatenetwork/accumulate/pkg/api/v3/p2p"
"gitlab.com/accumulatenetwork/accumulate/pkg/api/v3/p2p/dial"
"gitlab.com/accumulatenetwork/accumulate/protocol"
)

func InitRouter(ctx context.Context, node *p2p.Node, network string) (routing.Router, error) {
// Address of the network service for the directory partition
dirNetSvc := api.ServiceTypeNetwork.AddressFor(protocol.Directory)

// Verify the network service is running
tr, ok := node.Tracker().(*dial.PersistentTracker)
if !ok {
// If we're not using a persistent tracker, wait for the service
fmt.Println("Waiting for a live network service")
svcAddr, err := dirNetSvc.MultiaddrFor(network)
if err != nil {
return nil, err
}

err = node.WaitForService(ctx, svcAddr)
if err != nil {
return nil, err
}

} else {
// Check if we know of a suitable peer
var found bool
for _, peer := range tr.DB().Peers.Load() {
if peer.Network(network).Service(dirNetSvc).Last.Success != nil {
found = true
}
}

// If not then scan the network (synchronously)
if !found {
fmt.Println("Scanning for peers")
tr.ScanPeers(5 * time.Minute)
}
}

fmt.Println("Fetching routing information")
client := &message.Client{
Transport: &message.RoutedTransport{
Network: network,
Dialer: node.DialNetwork(),
Router: new(routing.MessageRouter),
},
}

ns, err := client.NetworkStatus(ctx, api.NetworkStatusOptions{})
if err != nil {
return nil, err
}

router, err := routing.NewStaticRouter(ns.Routing, nil)
if err != nil {
return nil, err
}

return router, nil
}
Loading

0 comments on commit c1cab75

Please sign in to comment.