Skip to content

Commit

Permalink
fix: log
Browse files Browse the repository at this point in the history
  • Loading branch information
alexgao001 committed Jul 29, 2024
1 parent eb37704 commit 9fd55eb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/docker-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,6 @@ jobs:
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
docker tag $IMAGE_NAME $IMAGE_ID:latest
docker push $IMAGE_ID:$VERSION
docker push $IMAGE_ID:latest
13 changes: 9 additions & 4 deletions core/blockarchiver/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"

bundlesdk "github.com/bnb-chain/greenfield-bundle-sdk/bundle"
)
Expand Down Expand Up @@ -124,6 +125,7 @@ func (c *Client) GetBundleBlocksByBlockNum(ctx context.Context, blockNum uint64)

// GetBundleBlocks returns the bundle blocks by object name
func (c *Client) GetBundleBlocks(ctx context.Context, objectName string) ([]*Block, error) {
log.Info("GetBundleBlocks", "objectName", objectName)
var urlStr string
parts := strings.Split(c.spHost, "//")
urlStr = parts[0] + "//" + c.bucketName + "." + parts[1] + "/" + objectName
Expand All @@ -134,34 +136,37 @@ func (c *Client) GetBundleBlocks(ctx context.Context, objectName string) ([]*Blo
}
resp, err := c.hc.Do(req)
if err != nil {
log.Error("failed to do request", "err", err.Error())
return nil, err
}
defer resp.Body.Close()

body, err := io.ReadAll(resp.Body)
if err != nil {
log.Error("failed to read data", "error", err.Error())
return nil, err
}

tempFile, err := os.CreateTemp("", "bundle")
if err != nil {
fmt.Printf("Failed to create temporary file: %v\n", err)
log.Error("Failed to create temporary file: %v\n", err)
return nil, err
}
defer os.Remove(tempFile.Name())
// Write the content to the temporary file
_, err = tempFile.Write(body)
if err != nil {
fmt.Printf("Failed to write downloaded bundle to file: %v\n", err)
log.Error("Failed to write downloaded bundle to file: %v\n", err)
return nil, err
}
defer tempFile.Close()

bundleObjects, err := bundlesdk.NewBundleFromFile(tempFile.Name())
if err != nil {
fmt.Printf("Failed to create bundle from file: %v\n", err)
log.Error("Failed to create bundle from file: %v\n", err)
return nil, err
}

var blocksInfo []*Block
for _, objMeta := range bundleObjects.GetBundleObjectsMeta() {
objFile, _, err := bundleObjects.GetObject(objMeta.Name)
Expand All @@ -184,7 +189,7 @@ func (c *Client) GetBundleBlocks(ctx context.Context, objectName string) ([]*Blo
}
blocksInfo = append(blocksInfo, blockInfo)
}

log.Info("fetched bundle of blocks", "number", blocksInfo[0].Number)
return blocksInfo, nil
}

Expand Down
7 changes: 5 additions & 2 deletions core/blockarchiver/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"math/big"
"strconv"
"strings"
"sync"

"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log"
"github.com/sasha-s/go-deadlock"
)

// JsonError represents an error in JSON format
Expand Down Expand Up @@ -123,7 +123,7 @@ type RequestLock struct {
// if the number is within any of the ranges, but we don't need to populate the lookup every time a new range is added.
rangeMap map[uint64]*Range
lookupMap map[uint64]*Range
mu sync.RWMutex
mu deadlock.RWMutex
}

// NewRequestLock creates a new RequestLock
Expand All @@ -145,6 +145,7 @@ func (rl *RequestLock) IsWithinAnyRange(num uint64) bool {
// AddRange adds a new range to the cache
func (rl *RequestLock) AddRange(from, to uint64) {
log.Info("adding range", "from", from, "to", to)
defer log.Info("added range", "from", from, "to", to)
rl.mu.Lock()
defer rl.mu.Unlock()
newRange := &Range{
Expand All @@ -157,11 +158,13 @@ func (rl *RequestLock) AddRange(from, to uint64) {
for i := from; i <= to; i++ {
rl.lookupMap[i] = newRange
}

}

// RemoveRange removes a range from the cache
func (rl *RequestLock) RemoveRange(from, to uint64) {
log.Info("removing range", "from", from, "to", to)
defer log.Info("removed range", "from", from, "to", to)
rl.mu.Lock()
defer rl.mu.Unlock()

Expand Down

0 comments on commit 9fd55eb

Please sign in to comment.