fix(roller): fix stack bug (#320)

Co-authored-by: HAOYUatHZ <37070449+HAOYUatHZ@users.noreply.github.com>
This commit is contained in:
Lawliet-Chan
2023-03-06 19:59:33 +08:00
committed by GitHub
parent e1ec4d1f05
commit 787bfcaa58
4 changed files with 17 additions and 36 deletions

View File

@@ -5,7 +5,7 @@ import (
"runtime/debug"
)
var tag = "alpha-v1.14"
var tag = "alpha-v1.15"
var commit = func() string {
if info, ok := debug.ReadBuildInfo(); ok {

View File

@@ -241,7 +241,7 @@ func (r *Roller) prove() error {
}
} else {
// when the roller has more than 3 times panic,
// it will omit to prove the task, submit StatusProofError and then Pop the task.
// it will omit to prove the task, submit StatusProofError and then Delete the task.
proofMsg = &message.ProofDetail{
Status: message.StatusProofError,
Error: "zk proving panic",
@@ -251,7 +251,7 @@ func (r *Roller) prove() error {
}
defer func() {
_, err = r.stack.Pop()
err = r.stack.Delete(task.Task.ID)
if err != nil {
log.Error("roller stack pop failed!", "err", err)
}

View File

@@ -81,28 +81,12 @@ func (s *Stack) Peek() (*ProvingTask, error) {
return traces, nil
}
// Pop pops the proving-task on the top of Stack.
func (s *Stack) Pop() (*ProvingTask, error) {
var value []byte
if err := s.Update(func(tx *bbolt.Tx) error {
var key []byte
// Delete pops the proving-task on the top of Stack.
func (s *Stack) Delete(taskID string) error {
return s.Update(func(tx *bbolt.Tx) error {
bu := tx.Bucket(bucket)
c := bu.Cursor()
key, value = c.Last()
return bu.Delete(key)
}); err != nil {
return nil, err
}
if len(value) == 0 {
return nil, ErrEmpty
}
task := &ProvingTask{}
err := json.Unmarshal(value, task)
if err != nil {
return nil, err
}
return task, nil
return bu.Delete([]byte(taskID))
})
}
// UpdateTimes udpates the roller prove times of the proving task.

View File

@@ -36,10 +36,12 @@ func TestStack(t *testing.T) {
}
for i := 2; i >= 0; i-- {
var pop *ProvingTask
pop, err = s.Pop()
var peek *ProvingTask
peek, err = s.Peek()
assert.NoError(t, err)
assert.Equal(t, strconv.Itoa(i), peek.Task.ID)
err = s.Delete(strconv.Itoa(i))
assert.NoError(t, err)
assert.Equal(t, strconv.Itoa(i), pop.Task.ID)
}
// test times
@@ -52,18 +54,13 @@ func TestStack(t *testing.T) {
}
err = s.Push(task)
assert.NoError(t, err)
pop, err := s.Pop()
assert.NoError(t, err)
err = s.Push(pop)
assert.NoError(t, err)
peek, err := s.Peek()
assert.NoError(t, err)
pop2, err := s.Pop()
assert.Equal(t, 0, peek.Times)
err = s.UpdateTimes(peek, 3)
assert.NoError(t, err)
assert.Equal(t, peek, pop2)
s.UpdateTimes(pop2, 1)
peek2, err := s.Peek()
assert.NoError(t, err)
assert.Equal(t, 1, pop2.Times)
assert.Equal(t, 3, peek2.Times)
}