Skip to content
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

fix(hardfork): fix tests and update for height 0 #1207

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 6 additions & 17 deletions block/fork.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ func (m *Manager) checkForkUpdate(ctx context.Context) error {
return err
}

if m.State.Height() == 0 {
return nil
}
lastBlock, err := m.Store.LoadBlock(m.State.Height())
if err != nil {
return err
Expand Down Expand Up @@ -154,27 +157,13 @@ func (m *Manager) handleSequencerForkTransition(instruction types.Instruction) {

// Create a new block with the consensus messages
m.Executor.AddConsensusMsgs(consensusMsgs...)

block, commit, err := m.produceBlock(true, nil)
if err != nil {
panic(fmt.Sprintf("produce block: %v", err))
}

err = m.applyBlock(block, commit, types.BlockMetaData{Source: types.Produced})
if err != nil {
panic(fmt.Sprintf("apply block: %v", err))
}
m.ProduceApplyGossipBlock(context.Background(), true)

// Create another block emtpy
block, commit, err = m.produceBlock(true, nil)
if err != nil {
panic(fmt.Sprintf("produce empty block: %v", err))
}

err = m.applyBlock(block, commit, types.BlockMetaData{Source: types.Produced})
m.ProduceApplyGossipBlock(context.Background(), true)

// Create Batch and send
_, err = m.CreateAndSubmitBatch(m.Conf.BatchSubmitBytes, false)
_, err := m.CreateAndSubmitBatch(m.Conf.BatchSubmitBytes, false)
if err != nil {
panic(fmt.Sprintf("create and submit batch: %v", err))
}
Expand Down
2 changes: 1 addition & 1 deletion block/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func TestProduceOnlyAfterSynced(t *testing.T) {
assert.True(t, manager.State.Height() == 0)

// enough time to sync and produce blocks
ctx, cancel := context.WithTimeout(context.Background(), time.Second*4)
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
defer cancel()
// Capture the error returned by manager.Start.

Expand Down
1 change: 1 addition & 0 deletions block/modes.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func (m *Manager) runAsProposer(ctx context.Context, eg *errgroup.Group) error {
uerrors.ErrGroupGoLog(eg, m.logger, func() error {
return m.SubmitLoop(ctx, bytesProducedC)
})

uerrors.ErrGroupGoLog(eg, m.logger, func() error {
bytesProducedC <- m.GetUnsubmittedBytes() // load unsubmitted bytes from previous run
return m.ProduceBlockLoop(ctx, bytesProducedC)
Expand Down
1 change: 1 addition & 0 deletions block/submit.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ func (m *Manager) GetUnsubmittedBytes() int {
}
total += block.SizeBytes() + commit.SizeBytes()
}

return total
}

Expand Down
4 changes: 2 additions & 2 deletions block/submit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,12 @@ func TestBatchSubmissionFailedSubmission(t *testing.T) {
assert.Zero(t, manager.LastSettlementHeight.Load())

// try to submit, we expect failure
slmock.On("SubmitBatch", mock.Anything, mock.Anything, mock.Anything).Return(fmt.Errorf("submit batch")).Once()
slmock.On("SubmitBatch", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(fmt.Errorf("submit batch")).Once()
_, err = manager.CreateAndSubmitBatch(manager.Conf.BatchSubmitBytes, false)
assert.Error(t, err)

// try to submit again, we expect success
slmock.On("SubmitBatch", mock.Anything, mock.Anything, mock.Anything).Return(nil).Once()
slmock.On("SubmitBatch", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil).Once()
manager.CreateAndSubmitBatch(manager.Conf.BatchSubmitBytes, false)
assert.EqualValues(t, manager.State.Height(), manager.LastSettlementHeight.Load())
}
Expand Down
7 changes: 5 additions & 2 deletions settlement/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,11 @@ type Client struct {
}

func (c *Client) GetRollapp() (*types.Rollapp, error) {
// TODO implement me
panic("implement me")
return &types.Rollapp{
RollappID: c.rollappID,
Revision: 0,
RevisionStartHeight: 1,
}, nil
}

var _ settlement.ClientI = (*Client)(nil)
Expand Down
Loading