/
batch.go
81 lines (72 loc) · 2.37 KB
/
batch.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package batch
import (
"errors"
"github.com/vitelabs/go-vite/interval/common"
)
var (
// ErrorArrivedToMax means that the maximum capacity has been reached for the batch
ErrorArrivedToMax = errors.New("arrived to max")
// ErrorReference mean that the dependency item(account or snapshot block) does not exist in chain or batch
ErrorReference = errors.New("refer not exist")
)
// Batch is a batch for block insertion.
type Batch interface {
// AddAItem add account block to Batch
AddAItem(item Item, sHash *common.Hash) error
// AddAItem add snapshot block to Batch
AddSItem(item Item) error
// Levels returns all levels for the Batch
Levels() []Level
// Size returns the number of items
Size() int
// Info returns the basic info for the Batch
Info() string
// Version returns the version for the Batch
Version() uint64
// Exists returns whether or not the hash is in the Batch
Exists(hash common.Hash) bool
// Batch runs the Batch
Batch(snapshotFn BucketExecutorFn, accountFn BucketExecutorFn) error
// Id returns the id of the Batch
Id() uint64
}
// Level is a bucket collection, and it cannot be inserted concurrently between level
type Level interface {
// Buckets returns all buckets in the level.
Buckets() []Bucket
// Add will add the item to the level.
Add(item Item) error
// SHash is snapshot hash for the level, will return nil for snapshot level.
SHash() *common.Hash
// Snapshot mean whether it is a snapshot level(just snapshot item can be added).
Snapshot() bool
// Index means the index of the level
Index() int
// Close means not accepting any item
Close()
Closed() bool
// Done mean all item have been added to chain
Done()
HasDone() bool
// The count of Items
Size() int
}
// Bucket is a item(account and snapshot block) collection for same address
type Bucket interface {
// Items returns all items
Items() []Item
// Owner mean the same address, it will return nil if all items are snapshot item.
Owner() *common.Address
}
// Item means a account block or a snapshot block
type Item interface {
// keys, accounts, snapshot
ReferHashes() ([]common.Hash, []common.Hash, *common.Hash)
// Owner will return nil if the item is the snapshot item.
Owner() *common.Address
Hash() common.Hash
Height() uint64
PrevHash() common.Hash
}
// BucketExecutorFn can insert a bucket
type BucketExecutorFn func(p Batch, l Level, bucket Bucket, version uint64) error