-
Notifications
You must be signed in to change notification settings - Fork 214
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
Add BlockSummary
type and related changes
#3143
Conversation
ed8e9d0
to
24f0c71
Compare
b7dbd9b
to
c6d5d50
Compare
bors try |
tryBuild succeeded: |
340ba99
to
d58cbaf
Compare
* The `Summary` constructor cannot occur yet, using "error" for this case is still ok. * Add `MaybeLight s` class which indicates whether an address discovery state support light-mode * Add `lightSync` field to `NetworkLayer`
d58cbaf
to
6901fbe
Compare
… with an efficient (<>) operation.
6901fbe
to
6468d57
Compare
bors try |
tryBuild failed: |
-- | ||
-- However, instead of storing the sequence of blocks of directly as a Haskell | ||
-- list, the 'BlockSummary' only provides a 'query' function | ||
-- which looks up all transactions associated to a given addresses. |
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.
in next installements we will extend that and allow discovery of other things, like stake keys, policy keys, certificates, etc. Right?
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.
All things that we need in order to do address discovery, indeed.
The type BlockSummary
is actually polymorphic in the addr
type, and I felt that it would be easier to understand if I kept calling it "address".
In the LightSummary
type, we currently instantiate this to addr = Either Address RewardAccount
— as this is all the information currently required by applyBlocks
.
} | ||
|
||
-- | Merge two lists in sorted order. Remove duplicate items. | ||
mergeOn :: Ord key => (a -> key) -> (a -> a -> a) -> [a] -> [a] -> [a] |
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.
would be good to include some examples here, just to better explain what to expect from mergeOn
. I wonder if there is no function like that in Data.List or Data.List.Extra...maybe we can use zipWith inside?
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.
Fair enough. mergeOn
is very similar to a merging function that one would use in a mergesort implementation. I'll add more documentation / an example.
-- NOTE: Currently used the full address, | ||
-- containing both payment and staking parts. | ||
-- We may want to query only for the payment part at some point. | ||
isRelevantTx addr = any ((addr ==) . address) . outputs . snd |
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 (is. ==) will be needed to generalize later as it only survives non-script case. For scripts we will need isShared, here maybe we should sneek isOurs, even at this moment. What do you think?
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.
Well, the thing is that in light-mode, we cannot use the isOurs
functions anymore — the blockchain data source will provide us with a query addr -> m txs
(instantiated to e.g. (Either Address RewardAccount) -> m ChainEvents
). Then, address discovery will have to put several addr
into this query rather than considering full blocks from the chain and filtering them.
The summarizeOnTxOut
and filterBlock
functions are intended for testing only. The plan is to test light-mode by comparing two paths:
list of blocks → filter into query → light-mode address discovery
list of blocks → node-mode address discovery
These functions help with the first →.
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.
yes, I see it. in light mode we use query
and it is up to caller using BlockSummary
how query
looks like. So it is upt to caller, ie. consumer of this abstraction, do deal with address management. It is the caller's responsibility
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.
Yes, exactly. Hence no isOurs
here.
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.
very nice abstractions introduced, I like always sorted by slot ChainEvents being monoid, BlockSummary
as we discussed. I wonder if isRelevantTx should not be already powered by using isOurs instead of == and prepared to accomodate isShared later. I am waiting for models' applyBlocks
impl and first integration test/setup in next PRs of this series
Co-authored-by: paweljakubas <[email protected]>
8a764ea
to
4068b27
Compare
bors merge |
Build succeeded: |
Issue number
ADP-1422, ADP-1425
Overview
Light-mode (Epic ADP-1422) aims to make synchronisation to the blockchain faster by trusting an off-chain source of aggregated blockchain data.
In this pull request, we add the
BlockSummary
type that represents transaction data contained in a contiguous sequence of blocks. Instead of storing a sequence ofBlock
directly, theBlockSummary
gives us a (monadic) query that can be used to obtain transaction data for specific addresses within that sequence.The idea is that the
query
will eventually call out to the off-chain source of aggregated blockchain data. Thefrom
andto
fields are necessary to preserve the sequential way of how cardano-wallet currently consumes blockchain data.This pull request mainly adds and rearranges types, and matches
lightSync
with theMaybeLight
type class. However, the implementation of production or consumption ofBlockSummary
will be tackled in later pull requests.Details
lightSync
to theNetworkLayer
. This field will eventually provide theBlockSummary
to aChainFollower
. It is set toNothing
for now.MaybeLight s
which indicates whether a wallet state supports address and transaction discovery withBlockSummary
. All instances are currently set toNothing
.BlockSummary
type with …addr = Either Address RewardAccount
. In other words, we can either get transaction data pertaining to a singleAddress
, or delegation information pertaining to aRewardAccount
.txs = ChainEvents
, which is a sequence ofBlockEvents
. In turn, the typeBlockEvents
contains transactions and delegations that appear within a single block; this can be the full block, or a subset of interest.BlockData
tags whether we are consuming a sequence ofBlock
, or aBlockSummary
. In the case of a summary, we include information from theMaybeLight
class in order to facilitate consumption.Comments
applyBlockToUTxO
to work withBlockEvents
instead ofBlock
.