-
Notifications
You must be signed in to change notification settings - Fork 40
/
update_chain_infos.go
65 lines (54 loc) · 1.78 KB
/
update_chain_infos.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
package relayer
import (
"context"
"reflect"
"sync"
"github.com/palomachain/pigeon/chain"
"github.com/palomachain/pigeon/chain/paloma"
"github.com/palomachain/pigeon/internal/liblog"
"github.com/palomachain/pigeon/internal/traits"
log "github.com/sirupsen/logrus"
)
func (r *Relayer) UpdateExternalChainInfos(ctx context.Context, _ sync.Locker) error {
logger := liblog.WithContext(ctx).WithField("component", "update-external-chain-infos")
logger.Info("updating external chain infos")
if err := r.buildProcessors(ctx, nil); err != nil {
logger.WithError(err).Error("couldn't build processors to update external chain info")
return err
}
externalAccounts := make([]chain.ExternalAccount, len(r.processors))
for i, v := range r.processors {
externalAccounts[i] = v.ExternalAccount()
}
chainInfos := make([]paloma.ChainInfoIn, len(externalAccounts))
for i, v := range externalAccounts {
traits := traits.Build(v.ChainReferenceID, r.mevClient)
logger.WithFields(log.Fields{
"chain-reference-id": v.ChainReferenceID,
"acc-address": v.Address,
"chain-type": v.ChainType,
"chain-traits": traits,
}).Info("adding chain info to payload")
chainInfos[i] = paloma.ChainInfoIn{
ChainReferenceID: v.ChainReferenceID,
AccAddress: v.Address,
ChainType: v.ChainType,
PubKey: v.PubKey,
Traits: traits,
}
}
if len(chainInfos) < 1 {
return nil
}
if reflect.DeepEqual(chainInfos, r.valCache.lastChainInfoRecord) {
logger.Info("Chain infos unchanged, skip sending...")
return nil
}
err := r.palomaClient.AddExternalChainInfo(ctx, chainInfos...)
if err != nil {
return err
}
logger.Info("Updated chain infos record sent, refreshing cache...")
r.valCache.lastChainInfoRecord = chainInfos
return nil
}