-
Notifications
You must be signed in to change notification settings - Fork 267
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 all 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 |
||
defer cancel() | ||
// 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())) | ||
} | ||
} | ||
} | ||
|
||
// Returns true if the proposal block is complete && | ||
|
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