-
Notifications
You must be signed in to change notification settings - Fork 26
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
enhancement: plugin interface #83
Merged
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
b96486c
enhancement: plugin interface
bb68599
lint
543bcf5
commentary
aa9d310
tighten unit test expectations around importer.Init() *genesis return…
f80f9d4
fix plugin docs: https://developer.algorand.org/docs/get-details/cond…
8b60bc3
small edits
f75141a
Update .markdownlint.yml
tzaffi 650bdb7
cherry pick changes from docs-staleness branch
88d7b8f
Update .gitignore
tzaffi 274aebf
Update .gitignore
tzaffi 155e5ec
do we actually need the Config() method?
0e4d628
remove Config() everywhere
0eae647
remove Config() everywhere
9a3a95c
flatten PluginMetadata interface into Plugin interface
eb3e4fb
all the interfaces have Init() + importer has GetGenesis()
da2a27a
unify Init() inside of Plugin interface
7b36bde
Merge remote-tracking branch 'upstream/master' into plugin-interface
1301f19
fix unit tests that are supposed to error
f9f93b9
ErrorContains not Error()
d2fff8e
fix algod_importer tests
6863d42
Merge branch 'master' into plugin-interface
414d08d
md lint
ae6768b
Update conduit/metrics/metrics.go
tzaffi 92a503d
assert that the genesis is non-nil when no error getting it
b8fef8f
add in missing zero-val'd errInit and errGetGen
5b114a0
add test case to trigger nil algod_importer genesis
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 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 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 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 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 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 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 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 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 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 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 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 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 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 |
---|---|---|
|
@@ -15,7 +15,6 @@ import ( | |
|
||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/sirupsen/logrus" | ||
"gopkg.in/yaml.v3" | ||
|
||
"github.com/algorand/go-algorand-sdk/v2/client/v2/algod" | ||
"github.com/algorand/go-algorand-sdk/v2/client/v2/common" | ||
|
@@ -55,6 +54,7 @@ type algodImporter struct { | |
ctx context.Context | ||
cancel context.CancelFunc | ||
mode int | ||
genesis *sdk.Genesis | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cache the genesis in the |
||
} | ||
|
||
//go:embed sample.yaml | ||
|
@@ -328,12 +328,12 @@ func (algodImp *algodImporter) catchupNode(network string, targetRound uint64) e | |
return err | ||
} | ||
|
||
func (algodImp *algodImporter) Init(ctx context.Context, initProvider data.InitProvider, cfg plugins.PluginConfig, logger *logrus.Logger) (*sdk.Genesis, error) { | ||
func (algodImp *algodImporter) Init(ctx context.Context, initProvider data.InitProvider, cfg plugins.PluginConfig, logger *logrus.Logger) error { | ||
algodImp.ctx, algodImp.cancel = context.WithCancel(ctx) | ||
algodImp.logger = logger | ||
err := cfg.UnmarshalConfig(&algodImp.cfg) | ||
if err != nil { | ||
return nil, fmt.Errorf("connect failure in unmarshalConfig: %v", err) | ||
return fmt.Errorf("connect failure in unmarshalConfig: %v", err) | ||
} | ||
|
||
// To support backwards compatibility with the daemon we default to archival mode | ||
|
@@ -347,13 +347,13 @@ func (algodImp *algodImporter) Init(ctx context.Context, initProvider data.InitP | |
case followerModeStr: | ||
algodImp.mode = followerMode | ||
default: | ||
return nil, fmt.Errorf("algod importer was set to a mode (%s) that wasn't supported", algodImp.cfg.Mode) | ||
return fmt.Errorf("algod importer was set to a mode (%s) that wasn't supported", algodImp.cfg.Mode) | ||
} | ||
|
||
var client *algod.Client | ||
u, err := url.Parse(algodImp.cfg.NetAddr) | ||
if err != nil { | ||
return nil, err | ||
return err | ||
} | ||
|
||
if u.Scheme != "http" && u.Scheme != "https" { | ||
|
@@ -362,34 +362,34 @@ func (algodImp *algodImporter) Init(ctx context.Context, initProvider data.InitP | |
} | ||
client, err = algod.MakeClient(algodImp.cfg.NetAddr, algodImp.cfg.Token) | ||
if err != nil { | ||
return nil, err | ||
return err | ||
} | ||
algodImp.aclient = client | ||
|
||
genesisResponse, err := client.GetGenesis().Do(ctx) | ||
genesisResponse, err := algodImp.aclient.GetGenesis().Do(algodImp.ctx) | ||
if err != nil { | ||
return nil, err | ||
return err | ||
} | ||
|
||
genesis := sdk.Genesis{} | ||
|
||
// Don't fail on unknown properties here since the go-algorand and SDK genesis types differ slightly | ||
err = json.LenientDecode([]byte(genesisResponse), &genesis) | ||
if err != nil { | ||
return nil, err | ||
return err | ||
} | ||
if reflect.DeepEqual(genesis, sdk.Genesis{}) { | ||
return nil, fmt.Errorf("unable to fetch genesis file from API at %s", algodImp.cfg.NetAddr) | ||
return fmt.Errorf("unable to fetch genesis file from API at %s", algodImp.cfg.NetAddr) | ||
} | ||
algodImp.genesis = &genesis | ||
|
||
err = algodImp.catchupNode(genesis.Network, uint64(initProvider.NextDBRound())) | ||
|
||
return &genesis, err | ||
return algodImp.catchupNode(genesis.Network, uint64(initProvider.NextDBRound())) | ||
} | ||
|
||
func (algodImp *algodImporter) Config() string { | ||
s, _ := yaml.Marshal(algodImp.cfg) | ||
return string(s) | ||
func (algodImp *algodImporter) GetGenesis() (*sdk.Genesis, error) { | ||
if algodImp.genesis != nil { | ||
return algodImp.genesis, nil | ||
} | ||
return nil, fmt.Errorf("algod importer is missing its genesis: GetGenesis() should be called only after Init()") | ||
} | ||
|
||
func (algodImp *algodImporter) Close() error { | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new interface method in use