Integrated heimdall gRPC server flow

This commit is contained in:
Krishna Upadhyaya 2022-07-26 18:08:25 +05:30
parent dbbacb8b19
commit 8de8a6815c
5 changed files with 20 additions and 14 deletions

View file

@ -35,7 +35,7 @@ var (
HeimdallgRPCAddressFlag = cli.StringFlag{ HeimdallgRPCAddressFlag = cli.StringFlag{
Name: "bor.heimdallgRPC", Name: "bor.heimdallgRPC",
Usage: "Address of Heimdall gRPC service", Usage: "Address of Heimdall gRPC service",
Value: ":3132", Value: "",
} }
// BorFlags all bor related flags // BorFlags all bor related flags

View file

@ -1,8 +1,7 @@
package heimdallgrpc package heimdallgrpc
import ( import (
"log" "github.com/ethereum/go-ethereum/log"
proto "github.com/maticnetwork/polyproto/heimdall" proto "github.com/maticnetwork/polyproto/heimdall"
"google.golang.org/grpc" "google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure" "google.golang.org/grpc/credentials/insecure"
@ -13,25 +12,24 @@ const (
) )
type HeimdallGRPCClient struct { type HeimdallGRPCClient struct {
conn *grpc.ClientConn conn *grpc.ClientConn
client proto.HeimdallClient client proto.HeimdallClient
closeCh chan struct{}
} }
func NewHeimdallGRPCClient(address string) *HeimdallGRPCClient { func NewHeimdallGRPCClient(address string) *HeimdallGRPCClient {
conn, err := grpc.Dial(address, grpc.WithTransportCredentials(insecure.NewCredentials())) conn, err := grpc.Dial(address, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil { if err != nil {
log.Fatalf("Failed to connect to Heimdall gRPC server: %v", err) log.Error("Failed to connect to Heimdall gRPC server: %v", err)
panic(err)
} }
return &HeimdallGRPCClient{ return &HeimdallGRPCClient{
conn: conn, conn: conn,
client: proto.NewHeimdallClient(conn), client: proto.NewHeimdallClient(conn),
closeCh: make(chan struct{}),
} }
} }
func (h *HeimdallGRPCClient) Close() { func (h *HeimdallGRPCClient) Close() {
close(h.closeCh) log.Debug("Shutdown detected, Closing Heimdall gRPC client")
h.conn.Close() h.conn.Close()
} }

View file

@ -9,7 +9,7 @@ import (
proto "github.com/maticnetwork/polyproto/heimdall" proto "github.com/maticnetwork/polyproto/heimdall"
) )
func (h *HeimdallGRPCClient) StateSyncEvents(fromID uint64, to int64) ([]*clerk.EventRecordWithTime, error) { func (h *HeimdallGRPCClient) StateSyncEvents(ctx context.Context, fromID uint64, to int64) ([]*clerk.EventRecordWithTime, error) {
eventRecords := make([]*clerk.EventRecordWithTime, 0) eventRecords := make([]*clerk.EventRecordWithTime, 0)
req := &proto.StateSyncEventsRequest{ req := &proto.StateSyncEventsRequest{

View file

@ -32,6 +32,7 @@ import (
"github.com/ethereum/go-ethereum/consensus/bor/contract" "github.com/ethereum/go-ethereum/consensus/bor/contract"
"github.com/ethereum/go-ethereum/consensus/bor/heimdall" //nolint:typecheck "github.com/ethereum/go-ethereum/consensus/bor/heimdall" //nolint:typecheck
"github.com/ethereum/go-ethereum/consensus/bor/heimdall/span" "github.com/ethereum/go-ethereum/consensus/bor/heimdall/span"
"github.com/ethereum/go-ethereum/consensus/bor/heimdallgrpc"
"github.com/ethereum/go-ethereum/consensus/clique" "github.com/ethereum/go-ethereum/consensus/clique"
"github.com/ethereum/go-ethereum/consensus/ethash" "github.com/ethereum/go-ethereum/consensus/ethash"
"github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core"
@ -249,7 +250,14 @@ func CreateConsensusEngine(stack *node.Node, chainConfig *params.ChainConfig, et
if ethConfig.WithoutHeimdall { if ethConfig.WithoutHeimdall {
return bor.New(chainConfig, db, blockchainAPI, spanner, nil, genesisContractsClient) return bor.New(chainConfig, db, blockchainAPI, spanner, nil, genesisContractsClient)
} else { } else {
return bor.New(chainConfig, db, blockchainAPI, spanner, heimdall.NewHeimdallClient(ethConfig.HeimdallURL), genesisContractsClient) var heimdallClient bor.IHeimdallClient
if ethConfig.HeimdallgRPCAddress != "" {
heimdallClient = heimdallgrpc.NewHeimdallGRPCClient(ethConfig.HeimdallgRPCAddress)
} else {
heimdallClient = heimdall.NewHeimdallClient(ethConfig.HeimdallURL)
}
return bor.New(chainConfig, db, blockchainAPI, spanner, heimdallClient, genesisContractsClient)
} }
} else { } else {
switch config.PowMode { switch config.PowMode {

View file

@ -414,7 +414,7 @@ func DefaultConfig() *Config {
Heimdall: &HeimdallConfig{ Heimdall: &HeimdallConfig{
URL: "http://localhost:1317", URL: "http://localhost:1317",
Without: false, Without: false,
GRPCAddress: ":3132", GRPCAddress: "",
}, },
SyncMode: "full", SyncMode: "full",
GcMode: "full", GcMode: "full",