Skip to content

Commit

Permalink
don't post the data to ipfs until after the proposal is made. Set Tim…
Browse files Browse the repository at this point in the history
…eout to 1.5 seconds

wrap error instead of panicking
  • Loading branch information
evan-forbes committed Mar 10, 2021
1 parent 07424dd commit 06f639e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
23 changes: 13 additions & 10 deletions consensus/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -1077,16 +1077,6 @@ func (cs *State) defaultDecideProposal(height int64, round int32) {
if block == nil {
return
}
// post data to ipfs
// TODO(evan): don't hard code context
if cs.IpfsAPI != nil {
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
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()
}
}

// Flush the WAL. Otherwise, we may not recompute the same proposal to sign,
Expand All @@ -1113,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)
// 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()
}
}

// Returns true if the proposal block is complete &&
Expand Down
2 changes: 1 addition & 1 deletion types/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ func (b *Block) PutBlock(ctx context.Context, api format.NodeAdder) error {
// recompute the eds
eds, err := rsmt2d.ComputeExtendedDataSquare(shares, rsmt2d.RSGF8, rsmt2d.NewDefaultTree)
if err != nil {
panic(fmt.Sprintf("unexpected error: %v", err))
return fmt.Errorf("failure to recompute the extended data square: %w", err)
}

// add namespaces to erasured shares and flatten the eds
Expand Down

0 comments on commit 06f639e

Please sign in to comment.