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{
Name: "bor.heimdallgRPC",
Usage: "Address of Heimdall gRPC service",
Value: ":3132",
Value: "",
}
// BorFlags all bor related flags

View file

@ -1,8 +1,7 @@
package heimdallgrpc
import (
"log"
"github.com/ethereum/go-ethereum/log"
proto "github.com/maticnetwork/polyproto/heimdall"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
@ -13,25 +12,24 @@ const (
)
type HeimdallGRPCClient struct {
conn *grpc.ClientConn
client proto.HeimdallClient
closeCh chan struct{}
conn *grpc.ClientConn
client proto.HeimdallClient
}
func NewHeimdallGRPCClient(address string) *HeimdallGRPCClient {
conn, err := grpc.Dial(address, grpc.WithTransportCredentials(insecure.NewCredentials()))
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{
conn: conn,
client: proto.NewHeimdallClient(conn),
closeCh: make(chan struct{}),
conn: conn,
client: proto.NewHeimdallClient(conn),
}
}
func (h *HeimdallGRPCClient) Close() {
close(h.closeCh)
log.Debug("Shutdown detected, Closing Heimdall gRPC client")
h.conn.Close()
}

View file

@ -9,7 +9,7 @@ import (
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)
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/heimdall" //nolint:typecheck
"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/ethash"
"github.com/ethereum/go-ethereum/core"
@ -249,7 +250,14 @@ func CreateConsensusEngine(stack *node.Node, chainConfig *params.ChainConfig, et
if ethConfig.WithoutHeimdall {
return bor.New(chainConfig, db, blockchainAPI, spanner, nil, genesisContractsClient)
} 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 {
switch config.PowMode {

View file

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