-
Notifications
You must be signed in to change notification settings - Fork 502
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
xdrill for ledgerCloseMeta #5568
base: master
Are you sure you want to change the base?
Conversation
exp/xdrill/ledger_test.go
Outdated
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.
How exhaustive do we want the testing to be?
exp/xdrill/ledger.go
Outdated
type Ledger struct { | ||
ledger *xdr.LedgerCloseMeta | ||
} |
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.
this struct definition would not work outside of the xdrill package. Although the Ledger
struct is exported, the ledger
field remains private to external packages. So, if you would not be able to construct a Ledger
instance outside of the xdrill package because you would not be able to reference the ledger
field.
To fix this issue you can make the ledger
field public:
type Ledger struct {
Ledger *xdr.LedgerCloseMeta
}
Alternatively, you could create a type definition:
type Ledger xdr.LedgerCloseMeta
func (l Ledger) Sequence() uint32 {
return uint32(l.ledger.LedgerHeaderHistoryEntry().Header.LedgerSeq)
}
Then to call the helper function you would cast your xdr.LedgerCloseMeta
value into an xdrill.Ledger
value so you could call the helper function:
package app
import (
"github.com/stellar/go/exp/xdrill"
"github.com/stellar/go/xdr"
)
func doSomething(ledger xdr.LedgerCloseMeta) {
l := xrill.Ledger(ledger)
seq := l.Sequence()
...
}
Or you could make the helper functions take the ledger parameter as the first argument:
func LedgerSequence(ledger xdr.LedgerCloseMeta) uint32 {
return uint32(ledger.LedgerHeaderHistoryEntry().Header.LedgerSeq)
}
IMO the cleanest API would be define helper functions like these in the xdr package directly on the LedgerCloseMeta
type. I think I missed the discussion about this decision. What was the motivation for defining a type equivalent to xdr.LedgerCloseMeta in the xdrill package?
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.
Ah oops yeah it should be public
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.
I forgot to mention one other possible solution, you could leave the ledger
field as private and expose a public constructor:
type Ledger struct {
ledger *xdr.LedgerCloseMeta
}
func NewLedger(ledger xdr.LedgerCloseMeta) Ledger {
return Ledger{ledger: &ledger}
}
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.
What was the motivation for defining a type equivalent to xdr.LedgerCloseMeta in the xdrill package?
Talked in slack. tl;dr - it's nicer for users as a separate package because they would be given a subset of only XDRill functions instead of all the functions/fields within xdr and ingest
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.
Updated functions to accept lcm as a param instead of the Ledger struct
d45b0fd
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.
Moved xdrill ledger functions to go/ingest/ledger
40d5057
exp/xdrill/utils/utils.go
Outdated
@@ -0,0 +1,128 @@ | |||
package utils |
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.
utils packages are generally discouraged in go:
https://google.github.io/styleguide/go/decisions.html#package-names
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.
Ah ok. What is the correct way to organize shared "utils"/"common" functions?
Would just renaming the package to xdrillutils
be good?
Or should I split it out into more descriptive packages like xdrillschemas
, xdrillconversions
?
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.
I think xdrillutils
is basically equivalent to utils
. In general, package names should be related to what the code actually does and if there is no unifying theme for all the code in the package then it could be that the code should be separated into multiple packages
for example, CreateSampleTx()
is used to generate to testing fixtures. you could argue that it doesn't need to even be exported outside of the testing files which use it.
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.
Yeah makes sense. I'll try splitting them up into more relevantly named packages. Maybe ChatGPT can offer some suggestions lol
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.
Moved util functions to relevant places
40d5057
PR Checklist
PR Structure
otherwise).
services/friendbot
, orall
ordoc
if the changes are broad or impact manypackages.
Thoroughness
.md
files, etc... affected by this change). Take a look in the
docs
folder for a given service,like this one.
Release planning
CHANGELOG.md
within the component folder structure. For example, if I changed horizon, then I updated (services/horizon/CHANGELOG.md. I add a new line item describing the change and reference to this PR. If I don't update a CHANGELOG, I acknowledge this PR's change may not be mentioned in future release notes.semver, or if it's mainly a patch change. The PR is targeted at the next
release branch if it's not a patch change.
What
github issue
xdrill functions for LedgerCloseMeta
Why
First commit for xdrill with the low level helper functions from the processors/transforms from stellar-etl for
history_ledgers
found hereKnown limitations