Skip to content
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/geth/chaincmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ The dumpgenesis command dumps the genesis block configuration in JSON format to
utils.HeimdallgRPCAddressFlag,
utils.RunHeimdallFlag,
utils.RunHeimdallArgsFlag,
utils.UseHeimdallAppFlag,
},
Category: "BLOCKCHAIN COMMANDS",
Description: `
Expand Down
8 changes: 4 additions & 4 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,10 +347,6 @@ func geth(ctx *cli.Context) error {
return fmt.Errorf("invalid command: %q", args[0])
}

prepare(ctx)
stack, backend := makeFullNode(ctx)
defer stack.Close()

if ctx.GlobalBool(utils.RunHeimdallFlag.Name) {
shutdownCtx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
defer stop()
Expand All @@ -360,6 +356,10 @@ func geth(ctx *cli.Context) error {
}()
}

prepare(ctx)
stack, backend := makeFullNode(ctx)
defer stack.Close()

startNode(ctx, stack, backend, false)
stack.Wait()
return nil
Expand Down
8 changes: 8 additions & 0 deletions cmd/utils/bor_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,20 @@ var (
Value: "",
}

// UseHeimdallApp flag for using internall heimdall app to fetch data
UseHeimdallAppFlag = cli.BoolFlag{
Name: "bor.useheimdallapp",
Usage: "Use child heimdall process to fetch data, Only works when bor.runheimdall is true",
}

// BorFlags all bor related flags
BorFlags = []cli.Flag{
HeimdallURLFlag,
WithoutHeimdallFlag,
HeimdallgRPCAddressFlag,
RunHeimdallFlag,
RunHeimdallArgsFlag,
UseHeimdallAppFlag,
}
)

Expand All @@ -82,6 +89,7 @@ func SetBorConfig(ctx *cli.Context, cfg *eth.Config) {
cfg.HeimdallgRPCAddress = ctx.GlobalString(HeimdallgRPCAddressFlag.Name)
cfg.RunHeimdall = ctx.GlobalBool(RunHeimdallFlag.Name)
cfg.RunHeimdallArgs = ctx.GlobalString(RunHeimdallArgsFlag.Name)
cfg.UseHeimdallApp = ctx.GlobalBool(UseHeimdallAppFlag.Name)
}

// CreateBorEthereum Creates bor ethereum object from eth.Config
Expand Down
1 change: 1 addition & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -2037,6 +2037,7 @@ func MakeChain(ctx *cli.Context, stack *node.Node) (chain *core.BlockChain, chai
HeimdallgRPCAddress: ctx.GlobalString(HeimdallgRPCAddressFlag.Name),
RunHeimdall: ctx.GlobalBool(RunHeimdallFlag.Name),
RunHeimdallArgs: ctx.GlobalString(RunHeimdallArgsFlag.Name),
UseHeimdallApp: ctx.GlobalBool(UseHeimdallAppFlag.Name),
})
engine = ethereum.Engine()
} else {
Expand Down
50 changes: 50 additions & 0 deletions consensus/bor/heimdallapp/checkpoint.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package heimdallapp

import (
"context"
"encoding/json"
Comment thread
0xKrishna marked this conversation as resolved.
Outdated

"github.com/ethereum/go-ethereum/consensus/bor/heimdall/checkpoint"
"github.com/ethereum/go-ethereum/log"

abci "github.com/tendermint/tendermint/abci/types"
)

func (h *HeimdallAppClient) FetchCheckpointCount(ctx context.Context) (int64, error) {
log.Info("Fetching checkpoint count")

hCtx := h.hApp.NewContext(true, abci.Header{Height: h.hApp.LastBlockHeight()})

res := h.hApp.CheckpointKeeper.GetACKCount(hCtx)

log.Info("Fetched checkpoint count")

return int64(res), nil
}

func (h *HeimdallAppClient) FetchCheckpoint(ctx context.Context, number int64) (*checkpoint.Checkpoint, error) {
log.Info("Fetching checkpoint", "number", number)

hCtx := h.hApp.NewContext(true, abci.Header{Height: h.hApp.LastBlockHeight()})

res, err := h.hApp.CheckpointKeeper.GetCheckpointByNumber(hCtx, uint64(number))
if err != nil {
return nil, err
}

log.Info("Fetched checkpoint", "number", number)

resBytes, err := json.Marshal(res)
if err != nil {
return nil, err
}

var checkpoint checkpoint.Checkpoint

err = json.Unmarshal(resBytes, &checkpoint)
Comment thread
0xKrishna marked this conversation as resolved.
Outdated
if err != nil {
return nil, err
}

return &checkpoint, nil
}
27 changes: 27 additions & 0 deletions consensus/bor/heimdallapp/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package heimdallapp

import (
"github.com/ethereum/go-ethereum/log"

"github.com/maticnetwork/heimdall/app"
"github.com/maticnetwork/heimdall/cmd/heimdalld/service"
)

const (
stateFetchLimit = 50
)

type HeimdallAppClient struct {
hApp *app.HeimdallApp
}

func NewHeimdallAppClient() *HeimdallAppClient {
return &HeimdallAppClient{
hApp: service.GetHeimdallApp(),
}
}

func (h *HeimdallAppClient) Close() {
// Nothing to close as of now
log.Debug("Shutdown detected, Closing Heimdall App conn")
Comment thread
0xKrishna marked this conversation as resolved.
Outdated
}
38 changes: 38 additions & 0 deletions consensus/bor/heimdallapp/span.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package heimdallapp

import (
"context"
"encoding/json"

"github.com/ethereum/go-ethereum/consensus/bor/heimdall/span"
"github.com/ethereum/go-ethereum/log"

abci "github.com/tendermint/tendermint/abci/types"
)

func (h *HeimdallAppClient) Span(ctx context.Context, spanID uint64) (*span.HeimdallSpan, error) {
log.Info("Fetching span", "spanID", spanID)

hCtx := h.hApp.NewContext(true, abci.Header{Height: h.hApp.LastBlockHeight()})

res, err := h.hApp.BorKeeper.GetSpan(hCtx, spanID)
if err != nil {
return nil, err
}

log.Info("Fetched span", "spanID", spanID)

resBytes, err := json.Marshal(res)
if err != nil {
return nil, err
}

var span span.HeimdallSpan

err = json.Unmarshal(resBytes, &span)
if err != nil {
return nil, err
}

return &span, nil
}
51 changes: 51 additions & 0 deletions consensus/bor/heimdallapp/state_sync.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package heimdallapp

import (
"context"
"encoding/json"
Comment thread
0xKrishna marked this conversation as resolved.
Outdated
"time"

"github.com/ethereum/go-ethereum/consensus/bor/clerk"

abci "github.com/tendermint/tendermint/abci/types"
)

func (h *HeimdallAppClient) StateSyncEvents(ctx context.Context, fromID uint64, to int64) ([]*clerk.EventRecordWithTime, error) {
totalRecords := make([]*clerk.EventRecordWithTime, 0)

hCtx := h.hApp.NewContext(true, abci.Header{Height: h.hApp.LastBlockHeight()})

for {
fromRecord, err := h.hApp.ClerkKeeper.GetEventRecord(hCtx, fromID)
if err != nil {
return nil, err
}

events, err := h.hApp.ClerkKeeper.GetEventRecordListWithTime(hCtx, fromRecord.RecordTime, time.Unix(to, 0), 1, stateFetchLimit)
if err != nil {
return nil, err
}

eventsByte, err := json.Marshal(events)
if err != nil {
return nil, err
}

var eventRecords []*clerk.EventRecordWithTime

err = json.Unmarshal(eventsByte, &eventRecords)
if err != nil {
return nil, err
}

totalRecords = append(totalRecords, eventRecords...)

if len(events) < stateFetchLimit {
break
}

fromID += uint64(stateFetchLimit)
}

return totalRecords, nil
}
8 changes: 7 additions & 1 deletion eth/ethconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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/heimdallapp"
"github.com/ethereum/go-ethereum/consensus/bor/heimdallgrpc"
"github.com/ethereum/go-ethereum/consensus/clique"
"github.com/ethereum/go-ethereum/consensus/ethash"
Expand Down Expand Up @@ -227,6 +228,9 @@ type Config struct {
// Arguments to pass to heimdall service
RunHeimdallArgs string

// Use child heimdall process to fetch data, Only works when RunHeimdall is true
UseHeimdallApp bool

// Bor logs flag
BorLogs bool

Expand Down Expand Up @@ -258,7 +262,9 @@ func CreateConsensusEngine(stack *node.Node, chainConfig *params.ChainConfig, et
return bor.New(chainConfig, db, blockchainAPI, spanner, nil, genesisContractsClient)
} else {
var heimdallClient bor.IHeimdallClient
if ethConfig.HeimdallgRPCAddress != "" {
if ethConfig.RunHeimdall && ethConfig.UseHeimdallApp {
heimdallClient = heimdallapp.NewHeimdallAppClient()
} else if ethConfig.HeimdallgRPCAddress != "" {
heimdallClient = heimdallgrpc.NewHeimdallGRPCClient(ethConfig.HeimdallgRPCAddress)
} else {
heimdallClient = heimdall.NewHeimdallClient(ethConfig.HeimdallURL)
Expand Down
Loading