/
integration.go
70 lines (57 loc) · 2.38 KB
/
integration.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
package integration
import (
"time"
"github.com/Fantom-foundation/lachesis-base/abft"
"github.com/Fantom-foundation/lachesis-base/utils/cachescale"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/p2p/simulations/adapters"
"github.com/status-im/keycard-go/hexutils"
"github.com/Ecosystem-Knowledge/go-ecoterium/gossip"
"github.com/Ecosystem-Knowledge/go-ecoterium/inter/validatorpk"
"github.com/Ecosystem-Knowledge/go-ecoterium/valkeystore"
"github.com/Ecosystem-Knowledge/go-ecoterium/vecmt"
)
var (
FlushIDKey = hexutils.HexToBytes("0068c2927bf842c3e9e2f1364494a33a752db334b9a819534bc9f17d2c3b4e5970008ff519d35a86f29fcaa5aae706b75dee871f65f174fcea1747f2915fc92158f6bfbf5eb79f65d16225738594bffb0c")
)
// NewIntegration creates gossip service for the integration test
func NewIntegration(ctx *adapters.ServiceContext, genesis InputGenesis, stack *node.Node) *gossip.Service {
gossipCfg := gossip.FakeConfig(1, cachescale.Identity)
cfg := Configs{
Opera: gossipCfg,
OperaStore: gossip.DefaultStoreConfig(cachescale.Identity),
Lachesis: abft.DefaultConfig(),
LachesisStore: abft.DefaultStoreConfig(cachescale.Identity),
VectorClock: vecmt.DefaultConfig(cachescale.Identity),
}
engine, dagIndex, gdb, _, _, blockProc := MakeEngine(DBProducer(ctx.Config.DataDir, cachescale.Identity), genesis, cfg)
_ = genesis.Close()
valKeystore := valkeystore.NewDefaultMemKeystore()
pubKey := validatorpk.PubKey{
Raw: crypto.FromECDSAPub(&ctx.Config.PrivateKey.PublicKey),
Type: validatorpk.Types.Secp256k1,
}
// unlock the key
_ = valKeystore.Add(pubKey, crypto.FromECDSA(ctx.Config.PrivateKey), validatorpk.FakePassword)
_ = valKeystore.Unlock(pubKey, validatorpk.FakePassword)
signer := valkeystore.NewSigner(valKeystore)
// find a genesis validator which corresponds to the key
for id, v := range gdb.GetEpochState().ValidatorProfiles {
if v.PubKey.String() == pubKey.String() {
gossipCfg.Emitter.Validator.ID = id
gossipCfg.Emitter.Validator.PubKey = v.PubKey
}
}
gossipCfg.Emitter.EmitIntervals.Max = 3 * time.Second
gossipCfg.Emitter.EmitIntervals.DoublesignProtection = 0
svc, err := gossip.NewService(stack, gossipCfg, gdb, signer, blockProc, engine, dagIndex)
if err != nil {
panic(err)
}
err = engine.Bootstrap(svc.GetConsensusCallbacks())
if err != nil {
return nil
}
return svc
}