Skip to content

Commit

Permalink
move base64 decode to unmarshal
Browse files Browse the repository at this point in the history
  • Loading branch information
mh0lt committed Sep 13, 2023
1 parent b5d2d94 commit bf75366
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 22 deletions.
4 changes: 2 additions & 2 deletions api/ui_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,8 @@ func NewUIHandler(
r.Get("/sessions/{sessionId}/nodes/{nodeId}/dbs/*", r.Tables)

r.Get("/sessions/{sessionId}/nodes/{nodeId}/reorgs", r.ReOrg)
r.Get("/sessions/{sessionId}/nodes/{nodeId}/bodies/download-stats", r.BodiesDownload)
r.Get("/sessions/{sessionId}/nodes/{nodeId}/headers/download-stats", r.HeadersDownload)
r.Get("/sessions/{sessionId}/nodes/{nodeId}/bodies/download-summary", r.BodiesDownload)
r.Get("/sessions/{sessionId}/nodes/{nodeId}/headers/download-summary", r.HeadersDownload)
r.Get("/sessions/{sessionId}/nodes/{nodeId}/sync-stages", r.SyncStages)

return r
Expand Down
29 changes: 12 additions & 17 deletions internal/erigon_node/remote_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ type RemoteDbReader interface {
Next(ctx context.Context) ([]byte, []byte, error)
}

type results [][2]string
type results [][2][]byte

func (r *results) UnmarshalJSON(json []byte) error {
func (r *results) UnmarshalJSON(json []byte) (err error) {

*r = nil

result := [2]string{}
result := [2][]byte{}

i := 0
ri := 0
Expand All @@ -97,17 +97,20 @@ func (r *results) UnmarshalJSON(json []byte) error {

switch json[i] {
case byte('"'):
var len int
len, value := tostr(json[i:])

len, result[ri] = tostr(json[i:])
i += len

if result[ri], err = base64.URLEncoding.DecodeString(value); err != nil {
return err
}

switch ri {
case 0:
ri++
case 1:
*r = append(*r, result)
result = [2]string{}
result = [2][]byte{}
ri = 0
}
case byte(':'), byte(','):
Expand Down Expand Up @@ -259,20 +262,12 @@ func (rc *RemoteCursor) Next(ctx context.Context) ([]byte, []byte, error) {
}
result := rc.results[0]

var k, v []byte
var e error
if k, e = base64.URLEncoding.DecodeString(result[0]); e != nil {
return nil, nil, fmt.Errorf("could not parse the key [%s]: %v", result[0], e)
}
if v, e = base64.URLEncoding.DecodeString(result[1]); e != nil {
return nil, nil, fmt.Errorf("could not parse the value [%s]: %v", result[1], e)
}
rc.results = rc.results[1:]

if len(rc.results) == 0 {
if e = rc.nextTableChunk(ctx, advance(k)); e != nil {
return k, v, e
if e := rc.nextTableChunk(ctx, advance(result[0])); e != nil {
return result[0], result[1], e
}
}
return k, v, e
return result[0], result[1], nil
}
4 changes: 1 addition & 3 deletions internal/erigon_node/reorg.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ func (c *NodeClient) executeFlush(writer io.Writer,
// return back total blocks set and wrong blocks
// if there are errors in the middle of processing will return back
// slice of errors
func (c *NodeClient) findReorgsInternally(ctx context.Context,
rc *RemoteCursor,
) (map[uint64][]byte, []uint64, []error) {
func (c *NodeClient) findReorgsInternally(ctx context.Context, rc *RemoteCursor) (map[uint64][]byte, []uint64, []error) {
var errors []error
set := make(map[uint64][]byte)
var wrongBlocks []uint64
Expand Down

0 comments on commit bf75366

Please sign in to comment.