-
Notifications
You must be signed in to change notification settings - Fork 291
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
Use the IPFS core object to post block data during proposal #178
Changes from 20 commits
eb421c8
09cfd50
8bb43e9
7778e00
b5f6c85
50b2a03
f13043d
c99bc38
4ad27a8
e5c2e17
2534b07
e74ed4e
e9ca0b9
742b62a
9dfa413
11c6313
b560b90
441e158
8e31785
417a817
d53622f
52fdd1b
4464a08
c07235d
3bf7bca
8cbaa42
c0f3d1c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ package consensus | |
|
||
import ( | ||
"bytes" | ||
"context" | ||
"errors" | ||
"fmt" | ||
"io/ioutil" | ||
|
@@ -11,7 +12,7 @@ import ( | |
"time" | ||
|
||
"github.com/gogo/protobuf/proto" | ||
|
||
ipfsapi "github.com/ipfs/interface-go-ipfs-core" | ||
cfg "github.com/lazyledger/lazyledger-core/config" | ||
cstypes "github.com/lazyledger/lazyledger-core/consensus/types" | ||
"github.com/lazyledger/lazyledger-core/crypto" | ||
|
@@ -92,6 +93,8 @@ type State struct { | |
// store blocks and commits | ||
blockStore sm.BlockStore | ||
|
||
IpfsAPI ipfsapi.CoreAPI | ||
|
||
// create and execute blocks | ||
blockExec *sm.BlockExecutor | ||
|
||
|
@@ -1100,6 +1103,19 @@ func (cs *State) defaultDecideProposal(height int64, round int32) { | |
} else if !cs.replayMode { | ||
cs.Logger.Error("enterPropose: Error signing proposal", "height", height, "round", round, "err", err) | ||
} | ||
|
||
// post data to ipfs | ||
// TODO(evan): don't hard code context and timeout | ||
if cs.IpfsAPI != nil { | ||
// longer timeouts result in block proposers failing to propose blocks in time. | ||
ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond*1500) | ||
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. There is a special Also, what's the rationale behind having timeout here? 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. Nice, I didn't know that. In this case, we need the timeout because |
||
// TODO: post data to IPFS in a goroutine | ||
err := block.PutBlock(ctx, cs.IpfsAPI.Dag().Pinning()) | ||
if err != nil { | ||
cs.Logger.Error(fmt.Sprintf("failure to post block data to IPFS: %s", err.Error())) | ||
} | ||
cancel() | ||
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. Nit: It seem more idiomatic to use 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. resolved with a defer 52fdd1b |
||
} | ||
} | ||
|
||
// Returns true if the proposal block is complete && | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -161,7 +161,7 @@ func RetrieveBlockData(ctx contex.Context, dah *DataAvailabilityHeader) (types.D | |
// the row to the Merkle Dag, in our case a Namespaced Merkle Tree. | ||
// Note, that this method could also fill the DA header. | ||
// The data will be pinned by default. | ||
func (b *Block) PutBlock(ctx contex.Context) error | ||
func (b *Block) PutBlock(ctx contex.Context, nodeAdder ipld.NodeAdder) error | ||
``` | ||
|
||
We now describe the lower-level library that will be used by above methods. | ||
|
@@ -185,15 +185,6 @@ func GetLeafData( | |
leafIndex uint32, | ||
totalLeafs uint32, // this corresponds to the extended square width | ||
) ([]byte, error) | ||
|
||
// PutLeaves takes the namespaced leaves, a row of the from the extended data square, | ||
// and calls nodes.DataSquareRowOrColumnRawInputParser of the ipld plugin. | ||
// The resulting ipld nodes are passed to a Batch calling AddMany: | ||
// https://github.com/ipfs/go-ipld-format/blob/d2e09424ddee0d7e696d01143318d32d0fb1ae63/batch.go#L29 | ||
// Note, that this method could also return the row and column roots. | ||
// Tha caller is responsible for making sure that the leaves are sorted by namespace ID. | ||
// The data will be pinned by default. | ||
func PutLeaves(ctx contex.Context, namespacedLeaves [][]byte) error | ||
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. The idea behind this was that we have this lower level method that has ipfs, contexts etc as a dependency and PutBlock would use that. But maybe that is still not optimal as it would just be an indirection and we'd still have a dependency to networking code in 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. Noted in #196. I think we should definitely add it back when we move |
||
``` | ||
|
||
`GetLeafData` can be used by above `ValidateAvailability` and `RetrieveBlock` and | ||
|
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.
Let's track minor todos like this this in a follup issue before we merge.
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.
For this case, we can pass-through context already, having an issue for that seems like an overmanagement :)
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.
It's not about management. But from my experience todos can be forgotten and hence it is good to capture them somewhere more visible. It does not need to be one issue per todo. We can collect all minor things like this in one issue (see for instance: #179).
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've tracked these todos in #204 in order to prevent github calling me out on twitter. 😄
https://twitter.com/github/status/1367885997527171073?s=20