Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/ethstorage/es-node into dev…
Browse files Browse the repository at this point in the history
…netfix
  • Loading branch information
syntrust committed Dec 4, 2023
2 parents 5f3f670 + 7f7dbdb commit 1f29539
Show file tree
Hide file tree
Showing 38 changed files with 1,447 additions and 662 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go
name: GitHub Actions ES
name: GoLang CI Build-Test
run-name: ${{ github.actor }} is push code to main 🚀
on:
push:
branches: [ "main" ]
pull_request:
branches:
- main
jobs:
build:
name: build-and-test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down
54 changes: 54 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: GoLang CI Lint
on:
pull_request:
branches:
- main

permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
# pull-requests: read

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: '1.20'
cache: false
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
# Require: The version of golangci-lint to use.
# When `install-mode` is `binary` (default) the value can be v1.2 or v1.2.3 or `latest` to use the latest version.
# When `install-mode` is `goinstall` the value can be v1.2.3, `latest`, or the hash of a commit.
version: v1.54

# Optional: working directory, useful for monorepos
# working-directory: somedir

# Optional: golangci-lint command line arguments.
#
# Note: By default, the `.golangci.yml` file should be at the root of the repository.
# The location of the configuration file can be changed by using `--config=`
# args: --timeout=30m --config=/my/path/.golangci.yml --issues-exit-code=0
args: --config=./golangci.yml

# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true

# Optional: if set to true, then all caching functionality will be completely disabled,
# takes precedence over all other caching options.
# skip-cache: true

# Optional: if set to true, then the action won't cache or restore ~/go/pkg.
# skip-pkg-cache: true

# Optional: if set to true, then the action won't cache or restore ~/.cache/go-build.
# skip-build-cache: true

# Optional: The mode to install golangci-lint. It can be 'binary' or 'goinstall'.
# install-mode: "goinstall"
42 changes: 42 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# This workflow will publish an es-node release with a pre-build executable

name: Publish
run-name: ${{ github.actor }} is publishing a release 🚀
on:
push:
tags:
- 'v*'
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.20'

- name: Build
run: |
make TARGETOS=linux TARGETARCH=amd64
mv cmd/es-node/es-node es-node.${{github.ref_name}}.linux-amd64
make TARGETOS=darwin TARGETARCH=amd64
mv cmd/es-node/es-node es-node.${{github.ref_name}}.darwin-amd64
make TARGETOS=darwin TARGETARCH=arm64
mv cmd/es-node/es-node es-node.${{github.ref_name}}.darwin-arm64
make TARGETOS=windows TARGETARCH=amd64
mv cmd/es-node/es-node es-node.${{github.ref_name}}.windows-amd64
- name: Create Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ github.ref }}
name: Release ${{github.ref_name}}
files: |
es-node.${{github.ref_name}}.linux-amd64
es-node.${{github.ref_name}}.darwin-amd64
es-node.${{github.ref_name}}.darwin-arm64
es-node.${{github.ref_name}}.windows-amd64
generate_release_notes: true
2 changes: 1 addition & 1 deletion GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ npm install -g [email protected]

- Use the following command to build es-node:
```sh
make
cd cmd/es-node && go build && cd ../..
```
- Alternatively, you can download the pre-built executable of the specific version from [the releases page](https://github.com/ethstorage/es-node/releases), such as es-node.v0.1.2.ubuntu, and then rename it using the following command:
```sh
Expand Down
6 changes: 3 additions & 3 deletions cmd/es-utils/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func SendBlobTx(

h := crypto.Keccak256Hash([]byte(`upfrontPayment()`))
callMsg := ethereum.CallMsg{
To: &to,
To: &to,
Data: h[:],
}
bs, err := client.CallContract(context.Background(), callMsg, new(big.Int).SetInt64(-2))
Expand All @@ -76,8 +76,8 @@ func SendBlobTx(
log.Crit("Invalid value param")
}

if res[0].(* big.Int).Cmp(val) == 1 {
val = res[0].(* big.Int)
if res[0].(*big.Int).Cmp(val) == 1 {
val = res[0].(*big.Int)
}

value256, overflow := uint256.FromBig(val)
Expand Down
74 changes: 37 additions & 37 deletions ethstorage/downloader/blob_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,61 +13,61 @@ import (
)

type BlobCache struct {
blocks map[common.Hash]*blockBlobs
mu sync.RWMutex
blocks map[common.Hash]*blockBlobs
mu sync.RWMutex
}

func NewBlobCache() *BlobCache {
return &BlobCache{
blocks: map[common.Hash]*blockBlobs{},
}
return &BlobCache{
blocks: map[common.Hash]*blockBlobs{},
}
}

func (c *BlobCache) SetBlockBlobs(block *blockBlobs) {
c.mu.Lock()
defer c.mu.Unlock()
c.blocks[block.hash] = block
c.mu.Lock()
defer c.mu.Unlock()
c.blocks[block.hash] = block
}

func (c *BlobCache) Blobs(hash common.Hash) []blob {
c.mu.RLock()
defer c.mu.RUnlock()
c.mu.RLock()
defer c.mu.RUnlock()

if _, exist := c.blocks[hash]; !exist {
return nil
}
if _, exist := c.blocks[hash]; !exist {
return nil
}

res := []blob{}
for _, blob := range(c.blocks[hash].blobs) {
res = append(res, *blob)
}
return res
res := []blob{}
for _, blob := range c.blocks[hash].blobs {
res = append(res, *blob)
}
return res
}

func (c *BlobCache) GetKeyValueByIndex(idx uint64, hash common.Hash) []byte {
c.mu.RLock()
defer c.mu.RUnlock()
for _, block := range(c.blocks) {
for _, blob := range(block.blobs) {
if blob.kvIndex.Uint64() == idx && bytes.Equal(blob.hash[0:ethstorage.HashSizeInContract], hash[0:ethstorage.HashSizeInContract]) {
return blob.data
}
}
}
return nil
c.mu.RLock()
defer c.mu.RUnlock()

for _, block := range c.blocks {
for _, blob := range block.blobs {
if blob.kvIndex.Uint64() == idx && bytes.Equal(blob.hash[0:ethstorage.HashSizeInContract], hash[0:ethstorage.HashSizeInContract]) {
return blob.data
}
}
}
return nil
}

// TODO: @Qiang An edge case that may need to be handled when Ethereum block is NOT finalized for a long time
// We may need to add a counter in SetBlockBlobs(), if the counter is greater than a threshold which means
// there has been a long time after last Cleanup, so we need to Cleanup anyway in SetBlockBlobs.
func (c *BlobCache) Cleanup(finalized uint64) {
c.mu.Lock()
defer c.mu.Unlock()
c.mu.Lock()
defer c.mu.Unlock()

for hash, block := range(c.blocks) {
if block.number <= finalized {
delete(c.blocks, hash)
}
}
}
for hash, block := range c.blocks {
if block.number <= finalized {
delete(c.blocks, hash)
}
}
}
6 changes: 3 additions & 3 deletions ethstorage/downloader/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
package downloader

type Config struct {
DownloadStart int64 // which block should we download the blobs from
DownloadDump string // where to dump the download blobs
DownloadThreadNum int // how many threads that will be used to download the blobs into storage file
DownloadStart int64 // which block should we download the blobs from
DownloadDump string // where to dump the download blobs
DownloadThreadNum int // how many threads that will be used to download the blobs into storage file
}
Loading

0 comments on commit 1f29539

Please sign in to comment.