Skip to content

Commit 36b0cd8

Browse files
authored
refactor: rename the Lava-named Go internals (MAG-2972) (#695)
* refactor: rename the Lava-named Go internals (MAG-2972) Not breaking: no wire name, flag or config key changes here. - packages: protocol/lavasession -> routersession, protocol/lavaprotocol -> relayprotocol, utils/lavaslices -> sliceutil - logging: utils/lavalog*.go -> utils/log*.go, utils.LavaFormatX -> utils.FormatX, LAVA_LOG_* -> LOG_* - errors: common.LavaError and the LavaErrorXxx family -> RouterError, LavaWrappedError -> RouterWrappedError - identifiers: PublicLavaAddress -> PublicAddress, utils.LavaMutex -> utils.Mutex, LavaDirectiveHeaders -> DirectiveHeaders, SPECIAL_LAVA_DIRECTIVE_HEADERS -> SPECIAL_DIRECTIVE_HEADERS, and the LAVA_ prefix off the header-name constants - test env vars: LAVA_BENCH_HUGE, LAVA_REVERIFY_*, LAVA_METRIC_RESET_TEST -> SMARTROUTER_* - test fixtures: lava@<name> provider ids -> provider@<name>, expected_lava_code -> expected_error_code Real Lava-chain addresses and REST paths in URL-parsing fixtures are left as they are. * refactor: finish the rename in a test name and six comments (MAG-2972) - TestRouterWrappedError_NilLavaErrIsSafe -> ..._NilRouterErrIsSafe: the test covers the RouterErr field, and the old field name was left in it - six test comments still called the logger "lavalog"; the files are utils/log*.go now - README: realign the routersession/ row of the package tree No behaviour change: one test function name, comments and a README row.
1 parent 2c132eb commit 36b0cd8

471 files changed

Lines changed: 6316 additions & 6316 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.golangci.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ linters:
8787
linters:
8888
- dupl
8989
text: "(upstream_selector|provider_optimizer)\\.go"
90-
- path: protocol/lavasession/consumer_session_manager\.go
90+
- path: protocol/routersession/consumer_session_manager\.go
9191
linters:
9292
- dupl
9393
text: "consumer_session_manager\\.go"

‎CODING_GUIDELINES.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ This document is an extension to [CONTRIBUTING](./CONTRIBUTING.md) and provides
3434
or query, so a raw `NodeUrl.Url` must never reach a log, an error returned to a
3535
client, a metric label or a span attribute. `utils.RedactURL` (and
3636
`NodeUrl.UrlStr()`, which uses it) is the display form; `utils.RedactSecrets`
37-
strips urls out of arbitrary text such as a `*url.Error` message. `LavaFormatLog`
37+
strips urls out of arbitrary text such as a `*url.Error` message. `FormatLog`
3838
applies it to every message and attribute, so ordinary logging is already safe —
3939
what needs care is any path that formats a url without going through it.
4040
* Request headers are credentials too — `auth-config.auth-headers` outbound, the

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ cmd/smartrouter/ — Standalone Smart Router binary
431431
protocol/ — Core protocol implementation
432432
chainlib/ — Chain-specific parsers and proxies
433433
rpcsmartrouter/ — Smart router server and relay logic
434-
lavasession/ — Session and connection management
434+
routersession/ — Session and connection management
435435
provideroptimizer/ — QoS-based upstream selection
436436
relaycore/ — Relay processing pipeline
437437
metrics/ — Prometheus metrics

‎docs/ERROR-REGISTRY-DESIGN.md‎

Lines changed: 43 additions & 43 deletions
Large diffs are not rendered by default.

‎docs/RELAY-END-EVENT.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ For `no_answer`, `rejected_before_dispatch` and `router_error`, the first rule t
172172
| Cross-validation could not be staffed (`insufficient-capacity`, `insufficient-groups`) | `PROTOCOL_INSUFFICIENT_PROVIDERS` |
173173
| Cross-validation found no quorum (`no-agreement`, `diversity-unmet`, `group-quorum-unmet`) | `PROTOCOL_HASH_CONSENSUS_ERROR` |
174174
| A `routerFault` | `PROTOCOL_RELAY_PROCESSING_FAILED` |
175-
| Empty provider pool (`lavasession.PairingListEmptyError`) | `PROTOCOL_NO_PROVIDERS` |
176-
| Every endpoint disabled (`lavasession.AllProviderEndpointsDisabledError`) | `PROTOCOL_ALL_ENDPOINTS_DISABLED` |
175+
| Empty provider pool (`routersession.PairingListEmptyError`) | `PROTOCOL_NO_PROVIDERS` |
176+
| Every endpoint disabled (`routersession.AllProviderEndpointsDisabledError`) | `PROTOCOL_ALL_ENDPOINTS_DISABLED` |
177177
| Pinned provider unavailable or already failed | `PROTOCOL_PROVIDER_UNAVAILABLE` |
178178
| Batch over the configured size (`chainlib.ErrBatchRequestSizeExceeded`) | `PROTOCOL_BATCH_SIZE_EXCEEDED` |
179179
| An unsubscribe of a subscription the client does not hold (`common.SubscriptionNotFoundError`) | `PROTOCOL_SUBSCRIPTION_NOT_FOUND` |

‎ecosystem/cache/command.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ longer DefaultExpirationForNonFinalized will reduce sync QoS for "latest" reques
2929
ctx := context.Background()
3030
logLevel, err := cmd.Flags().GetString(FlagLogLevel)
3131
if err != nil {
32-
utils.LavaFormatFatal("failed to read log level flag", err)
32+
utils.FormatFatal("failed to read log level flag", err)
3333
}
3434
utils.SetGlobalLoggingLevel(logLevel)
3535

@@ -39,7 +39,7 @@ longer DefaultExpirationForNonFinalized will reduce sync QoS for "latest" reques
3939

4040
metricsAddress, err := cmd.Flags().GetString(FlagMetricsAddress)
4141
if err != nil {
42-
utils.LavaFormatFatal("failed to read metrics address flag", err)
42+
utils.FormatFatal("failed to read metrics address flag", err)
4343
}
4444
Server(ctx, address, metricsAddress, cmd.Flags())
4545
return nil

‎ecosystem/cache/core/engine.go‎

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ var errChainTipUnreadable = errors.New("chain tip could not be read from the sto
7979
func (e *Engine) chainTip(ctx context.Context, chainId string) int64 {
8080
tip, fresh, err := e.Store.GetChainTip(ctx, ChainTipKey(chainId))
8181
if err != nil {
82-
utils.LavaFormatDebug("chain tip unreadable", utils.LogAttr("chainId", chainId), utils.LogAttr("error", err))
82+
utils.FormatDebug("chain tip unreadable", utils.LogAttr("chainId", chainId), utils.LogAttr("error", err))
8383
return tipReadFailed
8484
}
8585
if !fresh {
@@ -97,10 +97,10 @@ func (e *Engine) GetSharedTip(ctx context.Context, chainId, sharedStateId string
9797
key := SharedTipKey(chainId, sharedStateId)
9898
value, found, err := e.Store.GetInt64(ctx, key)
9999
if err != nil || !found {
100-
utils.LavaFormatInfo("Failed fetching state from cache for this user id", utils.LogAttr("id", key))
100+
utils.FormatInfo("Failed fetching state from cache for this user id", utils.LogAttr("id", key))
101101
return 0
102102
}
103-
utils.LavaFormatInfo("getting seen block cache", utils.LogAttr("id", key), utils.LogAttr("value", value))
103+
utils.FormatInfo("getting seen block cache", utils.LogAttr("id", key), utils.LogAttr("value", value))
104104
return value
105105
}
106106

@@ -111,7 +111,7 @@ func (e *Engine) SetSharedTip(ctx context.Context, chainId, sharedStateId string
111111
return
112112
}
113113
if err := e.Store.SetInt64IfGreaterOrEqual(ctx, SharedTipKey(chainId, sharedStateId), seenBlock, ttl); err != nil {
114-
utils.LavaFormatWarning("failed setting shared-state tip", err, utils.LogAttr("chainId", chainId))
114+
utils.FormatWarning("failed setting shared-state tip", err, utils.LogAttr("chainId", chainId))
115115
}
116116
}
117117

@@ -151,7 +151,7 @@ func (e *Engine) setBlocksHashesToHeights(ctx context.Context, chainId string, b
151151
for _, hashToHeight := range blocksHashesToHeights {
152152
if hashToHeight.Height >= 0 {
153153
if err := e.Store.SetHeight(ctx, HeightKey(chainId, hashToHeight.Hash), hashToHeight.Height, e.Policy.BlocksHashesToHeights); err != nil {
154-
utils.LavaFormatWarning("failed setting block hash to height", err, utils.LogAttr("chainId", chainId))
154+
utils.FormatWarning("failed setting block hash to height", err, utils.LogAttr("chainId", chainId))
155155
}
156156
}
157157
}
@@ -186,15 +186,15 @@ func (e *Engine) getRelayInner(ctx context.Context, relayCacheGet *relaytypes.Re
186186
return nil, NotFoundError
187187
}
188188
if cacheVal.Hash == nil {
189-
utils.LavaFormatDebug("returning response",
189+
utils.FormatDebug("returning response",
190190
utils.Attribute{Key: "cache_source", Value: cacheSource},
191191
utils.Attribute{Key: "hash", Value: "nil"},
192192
utils.Attribute{Key: "response_data", Value: parser.CapStringLen(string(cacheVal.Response.Data))},
193193
)
194194
return cacheVal.ToCacheReply(), nil
195195
}
196196
if bytes.Equal(cacheVal.Hash, relayCacheGet.BlockHash) {
197-
utils.LavaFormatDebug("returning response",
197+
utils.FormatDebug("returning response",
198198
utils.Attribute{Key: "cache_source", Value: cacheSource},
199199
utils.Attribute{Key: "hash", Value: "match"},
200200
utils.Attribute{Key: "response_data", Value: parser.CapStringLen(string(cacheVal.Response.Data))},
@@ -234,7 +234,7 @@ func (e *Engine) GetRelay(ctx context.Context, relayCacheGet *relaytypes.RelayCa
234234
relayCacheGet.RequestedBlock = replaceRequestedBlock(originalRequestedBlock, getLatestBlock)
235235
}
236236

237-
utils.LavaFormatDebug("Got Cache Get",
237+
utils.FormatDebug("Got Cache Get",
238238
utils.Attribute{Key: "request_hash", Value: string(relayCacheGet.RequestHash)},
239239
utils.Attribute{Key: "finalized", Value: relayCacheGet.Finalized},
240240
utils.Attribute{Key: "requested_block", Value: originalRequestedBlock},
@@ -273,7 +273,7 @@ func (e *Engine) GetRelay(ctx context.Context, relayCacheGet *relaytypes.RelayCa
273273

274274
if err == nil {
275275
if cacheReply.SeenBlock < min(relayCacheGet.SeenBlock, relayCacheGet.RequestedBlock) {
276-
err = utils.LavaFormatDebug("reply seen block is smaller than our expectations",
276+
err = utils.FormatDebug("reply seen block is smaller than our expectations",
277277
utils.LogAttr("cacheReply.SeenBlock", cacheReply.SeenBlock),
278278
utils.LogAttr("seenBlock", relayCacheGet.SeenBlock),
279279
)
@@ -290,7 +290,7 @@ func (e *Engine) GetRelay(ctx context.Context, relayCacheGet *relaytypes.RelayCa
290290
// context's own error rides along, so a timeout is classified as one.
291291
return cacheReply, false, errors.Join(StoreError, errChainTipUnreadable, ctx.Err())
292292
}
293-
err = utils.LavaFormatDebug("Requested block is invalid",
293+
err = utils.FormatDebug("Requested block is invalid",
294294
utils.LogAttr("requested block", relayCacheGet.RequestedBlock),
295295
utils.LogAttr("request_hash", string(relayCacheGet.RequestHash)),
296296
)
@@ -299,7 +299,7 @@ func (e *Engine) GetRelay(ctx context.Context, relayCacheGet *relaytypes.RelayCa
299299

300300
cacheReply.BlocksHashesToHeights = blockHashes
301301
if blockHashes != nil {
302-
utils.LavaFormatDebug("block hashes:", utils.LogAttr("hashes", blockHashes))
302+
utils.FormatDebug("block hashes:", utils.LogAttr("hashes", blockHashes))
303303
}
304304

305305
hit = cacheReply.Reply != nil
@@ -311,7 +311,7 @@ func (e *Engine) GetRelay(ctx context.Context, relayCacheGet *relaytypes.RelayCa
311311
// scalars.
312312
func (e *Engine) SetRelay(ctx context.Context, relayCacheSet *relaytypes.RelayCacheSet) error {
313313
if relayCacheSet.RequestedBlock < 0 {
314-
return utils.LavaFormatError("invalid relay cache set data, request block is negative", nil, utils.Attribute{Key: "requestBlock", Value: relayCacheSet.RequestedBlock})
314+
return utils.FormatError("invalid relay cache set data, request block is negative", nil, utils.Attribute{Key: "requestBlock", Value: relayCacheSet.RequestedBlock})
315315
}
316316
latestKnownBlock := int64(math.Max(float64(relayCacheSet.Response.LatestBlock), float64(relayCacheSet.SeenBlock)))
317317
// Same scoping as GetRelay: the entry and all of its bookkeeping land in the
@@ -321,7 +321,7 @@ func (e *Engine) SetRelay(ctx context.Context, relayCacheSet *relaytypes.RelayCa
321321

322322
cacheKey := RelayKey(relayCacheSet.Finalized, chainId, relayCacheSet.RequestHash, relayCacheSet.RequestedBlock)
323323
cacheValue := NewEnvelope(relayCacheSet.Response, relayCacheSet.BlockHash, relayCacheSet.Finalized, relayCacheSet.OptionalMetadata, latestKnownBlock, relayCacheSet.IsNodeError, relayCacheSet.StatusCode)
324-
utils.LavaFormatDebug("Got Cache Set",
324+
utils.FormatDebug("Got Cache Set",
325325
utils.Attribute{Key: "cacheKey", Value: cacheKey},
326326
utils.Attribute{Key: "finalized", Value: relayCacheSet.Finalized},
327327
utils.Attribute{Key: "requested_block", Value: relayCacheSet.RequestedBlock},
@@ -335,7 +335,7 @@ func (e *Engine) SetRelay(ctx context.Context, relayCacheSet *relaytypes.RelayCa
335335
ttl := e.Policy.ForRelayEntry(relayCacheSet.Finalized, relayCacheSet.IsNodeError, time.Duration(relayCacheSet.AverageBlockTime), relayCacheSet.BlockHash)
336336
var storeErr error
337337
if err := e.Store.SetEntry(ctx, cacheKey, &cacheValue, ttl); err != nil {
338-
utils.LavaFormatWarning("failed storing cache entry", err, utils.LogAttr("cacheKey", cacheKey))
338+
utils.FormatWarning("failed storing cache entry", err, utils.LogAttr("cacheKey", cacheKey))
339339
storeErr = errors.Join(StoreError, err)
340340
}
341341

@@ -347,7 +347,7 @@ func (e *Engine) SetRelay(ctx context.Context, relayCacheSet *relaytypes.RelayCa
347347
// yields to any write (MAG-3755) it must not be allowed to replace a real one.
348348
if latestKnownBlock > 0 {
349349
if err := e.Store.SetChainTipIfGreaterOrEqualOrStale(ctx, ChainTipKey(chainId), latestKnownBlock); err != nil {
350-
utils.LavaFormatWarning("failed setting chain tip", err, utils.LogAttr("chainId", relayCacheSet.ChainId))
350+
utils.FormatWarning("failed setting chain tip", err, utils.LogAttr("chainId", relayCacheSet.ChainId))
351351
}
352352
}
353353
e.setBlocksHashesToHeights(ctx, chainId, relayCacheSet.BlocksHashesToHeights)

‎ecosystem/cache/core/envelope.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func (cv *Envelope) ToCacheReply() *relaytypes.CacheRelayReply {
4040
if cv.IsCompressed && len(response.Data) > 0 {
4141
decompressed, err := decompressData(response.Data)
4242
if err != nil {
43-
utils.LavaFormatError("Failed to decompress cache data", err)
43+
utils.FormatError("Failed to decompress cache data", err)
4444
} else {
4545
response.Data = decompressed
4646
}
@@ -66,7 +66,7 @@ func NewEnvelope(response *relaytypes.RelayReply, hash []byte, finalized bool, o
6666

6767
compressed, isCompressed, err := compressData(response.Data)
6868
if err != nil {
69-
utils.LavaFormatWarning("Failed to compress cache data, storing uncompressed", err)
69+
utils.FormatWarning("Failed to compress cache data, storing uncompressed", err)
7070
} else if isCompressed {
7171
response.Data = compressed
7272
}

‎ecosystem/cache/endpoint_observations.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@ func (s *RelayerCacheServer) SetEndpointObservation(ctx context.Context, req *re
5959
applied, err := s.engine().PublishEndpointObservation(ctx, req.ChainId, req.ApiInterface, req.EndpointId, req.PodId, req.Block,
6060
time.Duration(req.TtlMs)*time.Millisecond)
6161
if err != nil {
62-
return nil, utils.LavaFormatError("invalid endpoint observation set", err,
62+
return nil, utils.FormatError("invalid endpoint observation set", err,
6363
utils.LogAttr("chainId", req.ChainId),
6464
utils.LogAttr("apiInterface", req.ApiInterface),
6565
utils.LogAttr("block", req.Block),
6666
)
6767
}
68-
utils.LavaFormatTrace("endpoint observation set",
68+
utils.FormatTrace("endpoint observation set",
6969
utils.LogAttr("chainId", req.ChainId),
7070
utils.LogAttr("apiInterface", req.ApiInterface),
7171
utils.LogAttr("block", req.Block),

‎ecosystem/cache/handlers.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func (s *RelayerCacheServer) FlushCache(ctx context.Context, req *emptypb.Empty)
118118
if err := s.engine().Purge(ctx); err != nil {
119119
return nil, err
120120
}
121-
utils.LavaFormatInfo("cache server flushed by FlushCache RPC")
121+
utils.FormatInfo("cache server flushed by FlushCache RPC")
122122
return &emptypb.Empty{}, nil
123123
}
124124

@@ -139,7 +139,7 @@ func (s *RelayerCacheServer) cacheMiss(ctx context.Context, errPrint error) {
139139
func (s *RelayerCacheServer) PrintCacheStats(ctx context.Context, desc string) {
140140
hits := atomic.LoadUint64(&s.cacheHits)
141141
misses := atomic.LoadUint64(&s.cacheMisses)
142-
_ = utils.LavaFormatDebug(desc,
142+
_ = utils.FormatDebug(desc,
143143
utils.Attribute{Key: "misses", Value: strconv.FormatUint(misses, 10)},
144144
utils.Attribute{Key: "hits", Value: strconv.FormatUint(hits, 10)},
145145
)

0 commit comments

Comments
 (0)