-
Notifications
You must be signed in to change notification settings - Fork 4
/
commiter.go
59 lines (46 loc) · 1.5 KB
/
commiter.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
package chain
import (
"github.com/meverselabs/meverse/common"
"github.com/meverselabs/meverse/common/hash"
"github.com/meverselabs/meverse/core/types"
)
// Committer enables to commit block with pre-executed context
type Committer interface {
Generators() ([]common.Address, error)
ValidateHeader(bh *types.Header) error
ExecuteBlockOnContext(b *types.Block, ctx *types.Context, SigMap map[hash.Hash256]common.Address) (types.Receipts, error)
ConnectBlockWithContext(b *types.Block, ctx *types.Context, receipts types.Receipts) error
NewContext() *types.Context
}
type chainCommiter struct {
cn *Chain
}
func NewChainCommiter(cn *Chain) *chainCommiter {
ct := &chainCommiter{
cn: cn,
}
return ct
}
func (ct *chainCommiter) Generators() ([]common.Address, error) {
return ct.cn.store.Generators()
}
func (ct *chainCommiter) ValidateHeader(bh *types.Header) error {
ct.cn.Lock()
defer ct.cn.Unlock()
return ct.cn.validateHeader(bh)
}
func (ct *chainCommiter) ExecuteBlockOnContext(b *types.Block, ctx *types.Context, sm map[hash.Hash256]common.Address) (types.Receipts, error) {
ct.cn.Lock()
defer ct.cn.Unlock()
return ct.cn.executeBlockOnContext(b, ctx, sm)
}
func (ct *chainCommiter) ConnectBlockWithContext(b *types.Block, ctx *types.Context, receipts types.Receipts) error {
ct.cn.Lock()
defer ct.cn.Unlock()
return ct.cn.connectBlockWithContext(b, ctx, receipts)
}
func (ct *chainCommiter) NewContext() *types.Context {
ct.cn.Lock()
defer ct.cn.Unlock()
return types.NewContext(ct.cn.store)
}