-
Notifications
You must be signed in to change notification settings - Fork 594
Heimdall App implementation #646
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 17 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
5eea894
Added flags to run heimdall as a child process
0xKrishna fc48365
Fix: Lint
0xKrishna 6f3b367
Fix btcd package dependency for CI
0xKrishna 28716b5
Update btcd package version
0xKrishna 1e62a45
Merge branch 'develop' into run-heimdall-flags
0xKrishna 79ca0e5
Try removing ambigious importts
0xKrishna de08a24
dev: fix: lint fix for parallel tests
marcello33 54a0d0a
remove delete for ambigious import
0xKrishna c77a3a0
Merge branch 'develop' into run-heimdall-flags
0xKrishna ff90276
Remove unwanted space
0xKrishna 8c7588f
Implemented heimdallApp package for bor-heimdall interaction
0xKrishna 69fa88d
Merge branch 'develop' into heimdallApp-implementation
0xKrishna 63ea44a
Fix go mod
0xKrishna d7f60ba
Added heimdallApp as heimdallClient option
0xKrishna 902d057
Fix lint and mark flags as WIP
0xKrishna 9758fc2
Added bor.useheimdallapp flag
0xKrishna a965685
Merge branch 'develop' into heimdallApp-implementation
0xKrishna 7438dbc
Use jsoniter
0xKrishna bbbcb2d
Merge branch 'develop' into heimdallApp-implementation
0xKrishna b8ec627
convert types
JekaMas 75f49ff
minor refactor
0xKrishna File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| package heimdallapp | ||
|
|
||
| import ( | ||
| "context" | ||
| "encoding/json" | ||
|
|
||
| "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) | ||
|
0xKrishna marked this conversation as resolved.
Outdated
|
||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return &checkpoint, nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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") | ||
|
0xKrishna marked this conversation as resolved.
Outdated
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| package heimdallapp | ||
|
|
||
| import ( | ||
| "context" | ||
| "encoding/json" | ||
|
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 | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.