/
emitter_world.go
72 lines (57 loc) · 1.84 KB
/
emitter_world.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
package gossip
import (
"math/big"
"sync/atomic"
"github.com/TechPay-io/sirius-base/hash"
"github.com/TechPay-io/sirius-base/inter/idx"
"github.com/ethereum/go-ethereum/core/types"
"github.com/TechPay-io/go-photon/evmcore"
"github.com/TechPay-io/go-photon/inter"
"github.com/TechPay-io/go-photon/utils/wgmutex"
"github.com/TechPay-io/go-photon/valkeystore"
"github.com/TechPay-io/go-photon/vecmt"
)
// emitterWorld implements emitter.World interface
type emitterWorld struct {
s *Service
*Store
*wgmutex.WgMutex
*evmcore.TxPool
valkeystore.SignerI
types.Signer
}
func (ew *emitterWorld) Check(emitted *inter.EventPayload, parents inter.Events) error {
// sanity check
return ew.s.checkers.Validate(emitted, parents.Interfaces())
}
func (ew *emitterWorld) Process(emitted *inter.EventPayload) error {
return ew.s.processEvent(emitted)
}
func (ew *emitterWorld) Broadcast(emitted *inter.EventPayload) {
// PM listens and will broadcast it
ew.s.feed.newEmittedEvent.Send(emitted)
}
func (ew *emitterWorld) Build(e *inter.MutableEventPayload, onIndexed func()) error {
return ew.s.buildEvent(e, onIndexed)
}
func (ew *emitterWorld) DagIndex() *vecmt.Index {
return ew.s.dagIndexer
}
func (ew *emitterWorld) IsBusy() bool {
return atomic.LoadUint32(&ew.s.eventBusyFlag) != 0 || atomic.LoadUint32(&ew.s.blockBusyFlag) != 0
}
func (ew *emitterWorld) IsSynced() bool {
return atomic.LoadUint32(&ew.s.pm.synced) != 0
}
func (ew *emitterWorld) PeersNum() int {
return ew.s.pm.peers.Len()
}
func (ew *emitterWorld) GetHeads(epoch idx.Epoch) hash.Events {
return ew.Store.GetHeadsSlice(epoch)
}
func (ew *emitterWorld) GetLastEvent(epoch idx.Epoch, from idx.ValidatorID) *hash.Event {
return ew.Store.GetLastEvent(epoch, from)
}
func (ew *emitterWorld) GetRecommendedGasPrice() *big.Int {
return ew.s.GetEvmStateReader().RecommendedMinGasPrice()
}