MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / observerFetchBlock

Method observerFetchBlock

worker/observer.go:35–98  ·  view source on GitHub ↗
(dbID proto.DatabaseID, nodeID proto.NodeID, count int32)

Source from the content-addressed store, hash-verified

33}
34
35func (dbms *DBMS) observerFetchBlock(dbID proto.DatabaseID, nodeID proto.NodeID, count int32) (
36 block *types.Block, realCount int32, err error) {
37 var (
38 pubKey *asymmetric.PublicKey
39 addr proto.AccountAddress
40 height int32
41 )
42
43 // node parameters
44 pubKey, err = kms.GetPublicKey(nodeID)
45 if err != nil {
46 log.WithFields(log.Fields{
47 "databaseID": dbID,
48 "nodeID": nodeID,
49 }).WithError(err).Warning("get public key failed in observerFetchBlock")
50 return
51 }
52
53 addr, err = crypto.PubKeyHash(pubKey)
54 if err != nil {
55 log.WithFields(log.Fields{
56 "databaseID": dbID,
57 "nodeID": nodeID,
58 }).WithError(err).Warning("generate addr failed in observerFetchBlock")
59 return
60 }
61
62 defer func() {
63 lf := log.WithFields(log.Fields{
64 "dbID": dbID,
65 "nodeID": nodeID,
66 "addr": addr.String(),
67 "count": count,
68 })
69
70 if err != nil {
71 lf.WithError(err).Debug("observer fetch block")
72 } else {
73 if block != nil {
74 lf = lf.WithField("block", block.BlockHash())
75 }
76 lf.WithField("height", height).Debug("observer fetch block")
77 }
78 }()
79
80 // check permission
81 err = dbms.checkPermission(addr, dbID, types.ReadQuery, nil)
82 if err != nil {
83 log.WithFields(log.Fields{
84 "databaseID": dbID,
85 "addr": addr,
86 }).WithError(err).Warning("permission deny")
87 return
88 }
89
90 rawDB, ok := dbms.dbMap.Load(dbID)
91 if !ok {
92 err = ErrNotExists

Callers 2

TestDBMSFunction · 0.95
ObserverFetchBlockMethod · 0.80

Calls 11

checkPermissionMethod · 0.95
GetPublicKeyFunction · 0.92
WithFieldsFunction · 0.92
PubKeyHashFunction · 0.92
WarningMethod · 0.80
WithErrorMethod · 0.80
DebugMethod · 0.80
WithFieldMethod · 0.80
StringMethod · 0.45
BlockHashMethod · 0.45
FetchBlockByCountMethod · 0.45

Tested by 1

TestDBMSFunction · 0.76