parent
6260d5a148
commit
2a7c32ca3f
|
@ -2,10 +2,13 @@ package guardiand
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/base64"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/certusone/wormhole/node/pkg/db"
|
"github.com/certusone/wormhole/node/pkg/db"
|
||||||
|
gossipv1 "github.com/certusone/wormhole/node/pkg/proto/gossip/v1"
|
||||||
publicrpcv1 "github.com/certusone/wormhole/node/pkg/proto/publicrpc/v1"
|
publicrpcv1 "github.com/certusone/wormhole/node/pkg/proto/publicrpc/v1"
|
||||||
"github.com/certusone/wormhole/node/pkg/publicrpc"
|
"github.com/certusone/wormhole/node/pkg/publicrpc"
|
||||||
ethcommon "github.com/ethereum/go-ethereum/common"
|
ethcommon "github.com/ethereum/go-ethereum/common"
|
||||||
|
@ -30,6 +33,7 @@ type nodePrivilegedService struct {
|
||||||
db *db.Database
|
db *db.Database
|
||||||
injectC chan<- *vaa.VAA
|
injectC chan<- *vaa.VAA
|
||||||
logger *zap.Logger
|
logger *zap.Logger
|
||||||
|
signedInC chan *gossipv1.SignedVAAWithQuorum
|
||||||
}
|
}
|
||||||
|
|
||||||
// adminGuardianSetUpdateToVAA converts a nodev1.GuardianSetUpdate message to its canonical VAA representation.
|
// adminGuardianSetUpdateToVAA converts a nodev1.GuardianSetUpdate message to its canonical VAA representation.
|
||||||
|
@ -200,7 +204,7 @@ func (s *nodePrivilegedService) InjectGovernanceVAA(ctx context.Context, req *no
|
||||||
return &nodev1.InjectGovernanceVAAResponse{Digests: digests}, nil
|
return &nodev1.InjectGovernanceVAAResponse{Digests: digests}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// fetchMissing attempts to backfill a gap by fetching missing signed VAAs from the network.
|
// fetchMissing attempts to backfill a gap by fetching and storing missing signed VAAs from the network.
|
||||||
// Returns true if the gap was filled, false otherwise.
|
// Returns true if the gap was filled, false otherwise.
|
||||||
func (s *nodePrivilegedService) fetchMissing(
|
func (s *nodePrivilegedService) fetchMissing(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
|
@ -242,12 +246,50 @@ func (s *nodePrivilegedService) fetchMissing(
|
||||||
resp.Body.Close()
|
resp.Body.Close()
|
||||||
continue
|
continue
|
||||||
case http.StatusOK:
|
case http.StatusOK:
|
||||||
|
type getVaaResp struct {
|
||||||
|
VaaBytes string `json:"vaaBytes"`
|
||||||
|
}
|
||||||
|
var respBody getVaaResp
|
||||||
|
if err := json.NewDecoder(resp.Body).Decode(&respBody); err != nil {
|
||||||
|
resp.Body.Close()
|
||||||
|
s.logger.Warn("failed to decode VAA response",
|
||||||
|
zap.String("node", node),
|
||||||
|
zap.String("chain", chain.String()),
|
||||||
|
zap.String("address", addr),
|
||||||
|
zap.Uint64("sequence", seq),
|
||||||
|
zap.Error(err),
|
||||||
|
)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// base64 decode the VAA bytes
|
||||||
|
vaaBytes, err := base64.StdEncoding.DecodeString(respBody.VaaBytes)
|
||||||
|
if err != nil {
|
||||||
|
resp.Body.Close()
|
||||||
|
s.logger.Warn("failed to decode VAA body",
|
||||||
|
zap.String("node", node),
|
||||||
|
zap.String("chain", chain.String()),
|
||||||
|
zap.String("address", addr),
|
||||||
|
zap.Uint64("sequence", seq),
|
||||||
|
zap.Error(err),
|
||||||
|
)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
s.logger.Info("backfilled VAA",
|
s.logger.Info("backfilled VAA",
|
||||||
zap.Uint16("chain", uint16(chain)),
|
zap.Uint16("chain", uint16(chain)),
|
||||||
zap.String("address", addr),
|
zap.String("address", addr),
|
||||||
zap.Uint64("sequence", seq),
|
zap.Uint64("sequence", seq),
|
||||||
|
zap.Int("numBytes", len(vaaBytes)),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Inject into the gossip signed VAA receive path.
|
||||||
|
// This has the same effect as if the VAA was received from the network
|
||||||
|
// (verifying signature, publishing to BigTable, storing in local DB...).
|
||||||
|
s.signedInC <- &gossipv1.SignedVAAWithQuorum{
|
||||||
|
Vaa: vaaBytes,
|
||||||
|
}
|
||||||
|
|
||||||
resp.Body.Close()
|
resp.Body.Close()
|
||||||
return true, nil
|
return true, nil
|
||||||
default:
|
default:
|
||||||
|
@ -300,7 +342,7 @@ func (s *nodePrivilegedService) FindMissingMessages(ctx context.Context, req *no
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func adminServiceRunnable(logger *zap.Logger, socketPath string, injectC chan<- *vaa.VAA, db *db.Database, gst *common.GuardianSetState) (supervisor.Runnable, error) {
|
func adminServiceRunnable(logger *zap.Logger, socketPath string, injectC chan<- *vaa.VAA, signedInC chan *gossipv1.SignedVAAWithQuorum, db *db.Database, gst *common.GuardianSetState) (supervisor.Runnable, error) {
|
||||||
// Delete existing UNIX socket, if present.
|
// Delete existing UNIX socket, if present.
|
||||||
fi, err := os.Stat(socketPath)
|
fi, err := os.Stat(socketPath)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -336,6 +378,7 @@ func adminServiceRunnable(logger *zap.Logger, socketPath string, injectC chan<-
|
||||||
injectC: injectC,
|
injectC: injectC,
|
||||||
db: db,
|
db: db,
|
||||||
logger: logger.Named("adminservice"),
|
logger: logger.Named("adminservice"),
|
||||||
|
signedInC: signedInC,
|
||||||
}
|
}
|
||||||
|
|
||||||
publicrpcService := publicrpc.NewPublicrpcServer(logger, db, gst)
|
publicrpcService := publicrpc.NewPublicrpcServer(logger, db, gst)
|
||||||
|
|
|
@ -513,7 +513,7 @@ func runNode(cmd *cobra.Command, args []string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// local admin service socket
|
// local admin service socket
|
||||||
adminService, err := adminServiceRunnable(logger, *adminSocketPath, injectC, db, gst)
|
adminService, err := adminServiceRunnable(logger, *adminSocketPath, injectC, signedInC, db, gst)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Fatal("failed to create admin service socket", zap.Error(err))
|
logger.Fatal("failed to create admin service socket", zap.Error(err))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue