erigon-pulse/consensus/bor/heimdallgrpc/client.go
Mark Holt 529d359ca6
Bor span testing (#7897)
An update to the devnet to introduce a local heimdall to facilitate
multiple validators without the need for an external process, and hence
validator registration/staking etc.

In this initial release only span generation is supported.  

It has the following changes:

* Introduction of a local grpc heimdall interface
* Allocation of accounts via a devnet account generator ()
* Introduction on 'Services' for the network config

"--chain bor-devnet --bor.localheimdall" will run a 2 validator network
with a local service
"--chain bor-devnet --bor.withoutheimdall" will sun a single validator
with no heimdall service as before

---------

Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro-2.local>
2023-07-18 09:47:04 +01:00

54 lines
1.4 KiB
Go

package heimdallgrpc
import (
"time"
grpc_retry "github.com/grpc-ecosystem/go-grpc-middleware/retry"
"github.com/ledgerwatch/log/v3"
proto "github.com/maticnetwork/polyproto/heimdall"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials/insecure"
)
const (
stateFetchLimit = 50
)
type HeimdallGRPCClient struct {
conn *grpc.ClientConn
client proto.HeimdallClient
logger log.Logger
}
func NewHeimdallGRPCClient(address string, logger log.Logger) *HeimdallGRPCClient {
opts := []grpc_retry.CallOption{
grpc_retry.WithMax(10000),
grpc_retry.WithBackoff(grpc_retry.BackoffLinear(5 * time.Second)),
grpc_retry.WithCodes(codes.Internal, codes.Unavailable, codes.Aborted, codes.NotFound),
}
conn, err := grpc.Dial(address,
grpc.WithStreamInterceptor(grpc_retry.StreamClientInterceptor(opts...)),
grpc.WithUnaryInterceptor(grpc_retry.UnaryClientInterceptor(opts...)),
grpc.WithTransportCredentials(insecure.NewCredentials()),
)
if err != nil {
logger.Crit("Failed to connect to Heimdall gRPC", "error", err)
}
logger.Info("Connected to Heimdall gRPC server", "address", address)
return &HeimdallGRPCClient{
conn: conn,
client: proto.NewHeimdallClient(conn),
logger: logger,
}
}
func (h *HeimdallGRPCClient) Close() {
h.logger.Debug("Shutdown detected, Closing Heimdall gRPC client")
h.conn.Close()
}