Skip to content
This repository has been archived by the owner on Sep 23, 2023. It is now read-only.

Commit

Permalink
merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
AskAlexSharov committed Sep 6, 2023
2 parents 3b8a88a + cf6e038 commit e6c0ae3
Show file tree
Hide file tree
Showing 90 changed files with 5,995 additions and 2,617 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ jobs:
if: matrix.os == 'ubuntu-20.04'
uses: golangci/golangci-lint-action@v3
with:
version: v1.52
version: v1.54

- name: Lint source code licenses
if: matrix.os == 'ubuntu-20.04'
run: make lint-licenses-deps lint-licenses

- name: Test win
if: matrix.os == 'windows-2022'
Expand Down
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ linters:
- unused
- performance
disable:
- gosec
- exhaustive
- musttag
- contextcheck
Expand Down
14 changes: 11 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ $(GOBINREL):

$(GOBINREL)/protoc: | $(GOBINREL)
$(eval PROTOC_TMP := $(shell mktemp -d))
curl -sSL https://github.com/protocolbuffers/protobuf/releases/download/v23.3/protoc-23.3-$(PROTOC_OS)-$(ARCH).zip -o "$(PROTOC_TMP)/protoc.zip"
curl -sSL https://github.com/protocolbuffers/protobuf/releases/download/v24.2/protoc-24.2-$(PROTOC_OS)-$(ARCH).zip -o "$(PROTOC_TMP)/protoc.zip"
cd "$(PROTOC_TMP)" && unzip protoc.zip
cp "$(PROTOC_TMP)/bin/protoc" "$(GOBIN)"
mkdir -p "$(PROTOC_INCLUDE)"
Expand Down Expand Up @@ -71,7 +71,7 @@ mocks: $(GOBINREL)/moq
rm -f gointerfaces/sentry/mocks.go
PATH="$(GOBIN):$(PATH)" go generate ./...

lint: $(GOBINREL)/golangci-lint
lintci: $(GOBINREL)/golangci-lint
@"$(GOBIN)/golangci-lint" run --config ./.golangci.yml

# force re-make golangci-lint
Expand All @@ -80,11 +80,19 @@ lintci-deps-clean: golangci-lint-clean

# download and build golangci-lint (https://golangci-lint.run)
$(GOBINREL)/golangci-lint: | $(GOBINREL)
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b "$(GOBIN)" v1.53.2
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b "$(GOBIN)" v1.54.2

golangci-lint-clean:
rm -f "$(GOBIN)/golangci-lint"

lint-licenses-deps:
@./tools/licenses_check.sh --install-deps
lint-licenses:
@./tools/licenses_check.sh

lint-deps: lintci-deps lint-licenses-deps
lint: lintci lint-licenses

test:
$(GOTEST) --count 1 -p 2 ./...

Expand Down
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,22 @@
# erigon-lib
Dependencies of Erigon project, rewritten from scratch and licensed under Apache 2.0

## Dev workflow

In erigon folder create go.work file (it’s already in .gitignore)
```
go 1.20
use (
.
./../erigon-lib
)
```

Create PR in erigon-lib, don’t merge PR, refer from erigon to non-merged erigon-lib branch (commit) by:
go get github.com/ledgerwatch/erigon-lib/kv@<commit_hash>

Create Erigon PR

When both CI are green - merge 2 PR. That’s it.
92 changes: 91 additions & 1 deletion chain/chain_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,8 @@ type BorConfig struct {

IndoreBlock *big.Int `json:"indoreBlock"` // Indore switch block (nil = no fork, 0 = already on indore)
StateSyncConfirmationDelay map[string]uint64 `json:"stateSyncConfirmationDelay"` // StateSync Confirmation Delay, in seconds, to calculate `to`

sprints sprints
}

// String implements the stringer interface, returning the consensus engine details.
Expand All @@ -428,7 +430,62 @@ func (c *BorConfig) CalculateProducerDelay(number uint64) uint64 {
}

func (c *BorConfig) CalculateSprint(number uint64) uint64 {
return borKeyValueConfigHelper(c.Sprint, number)
if c.sprints == nil {
c.sprints = asSprints(c.Sprint)
}

for i := 0; i < len(c.sprints)-1; i++ {
if number >= c.sprints[i].from && number < c.sprints[i+1].from {
return c.sprints[i].size
}
}

return c.sprints[len(c.sprints)-1].size
}

func (c *BorConfig) CalculateSprintCount(from, to uint64) int {
switch {
case from > to:
return 0
case from < to:
to--
}

if c.sprints == nil {
c.sprints = asSprints(c.Sprint)
}

count := uint64(0)
startCalc := from

zeroth := func(boundary uint64, size uint64) uint64 {
if boundary%size == 0 {
return 1
}

return 0
}

for i := 0; i < len(c.sprints)-1; i++ {
if startCalc >= c.sprints[i].from && startCalc < c.sprints[i+1].from {
if to >= c.sprints[i].from && to < c.sprints[i+1].from {
if startCalc == to {
return int(count + zeroth(startCalc, c.sprints[i].size))
}
return int(count + zeroth(startCalc, c.sprints[i].size) + (to-startCalc)/c.sprints[i].size)
} else {
endCalc := c.sprints[i+1].from - 1
count += zeroth(startCalc, c.sprints[i].size) + (endCalc-startCalc)/c.sprints[i].size
startCalc = endCalc + 1
}
}
}

if startCalc == to {
return int(count + zeroth(startCalc, c.sprints[len(c.sprints)-1].size))
}

return int(count + zeroth(startCalc, c.sprints[len(c.sprints)-1].size) + (to-startCalc)/c.sprints[len(c.sprints)-1].size)
}

func (c *BorConfig) CalculateBackupMultiplier(number uint64) uint64 {
Expand Down Expand Up @@ -499,6 +556,39 @@ func sortMapKeys(m map[string]uint64) []string {
return keys
}

type sprint struct {
from, size uint64
}

type sprints []sprint

func (s sprints) Len() int {
return len(s)
}

func (s sprints) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
}

func (s sprints) Less(i, j int) bool {
return s[i].from < s[j].from
}

func asSprints(configSprints map[string]uint64) sprints {
sprints := make(sprints, len(configSprints))

i := 0
for key, value := range configSprints {
sprints[i].from, _ = strconv.ParseUint(key, 10, 64)
sprints[i].size = value
i++
}

sort.Sort(sprints)

return sprints
}

// Rules is syntactic sugar over Config. It can be used for functions
// that do not have or require information about the block.
//
Expand Down
24 changes: 0 additions & 24 deletions chain/protocol_param.go

This file was deleted.

25 changes: 12 additions & 13 deletions commitment/bin_patricia_hashed.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func binToCompact(bin []byte) []byte {
binary.BigEndian.PutUint16(compact, uint16(len(bin)))
for i := 0; i < len(bin); i++ {
if bin[i] != 0 {
compact[2+i/8] |= (byte(1) << (i % 8))
compact[2+i/8] |= byte(1) << (i % 8)
}
}
return compact
Expand Down Expand Up @@ -804,10 +804,9 @@ func (bph *BinPatriciaHashed) needUnfolding(hashedKey []byte) int {
if cell.hl == 0 {
// cell is empty, no need to unfold further
return 0
} else {
// unfold branch node
return 1
}
// unfold branch node
return 1
}
cpl := commonPrefixLen(hashedKey[depth:], cell.downHashedKey[:cell.downHashedLen-1])
if bph.trace {
Expand Down Expand Up @@ -1028,11 +1027,11 @@ func (bph *BinPatriciaHashed) fold() (branchData BranchData, updateKey []byte, e
} else if upDepth == halfKeySize {
// Special case - all storage items of an account have been deleted, but it does not automatically delete the account, just makes it empty storage
// Therefore we are not propagating deletion upwards, but turn it into a modification
bph.touchMap[row-1] |= (uint16(1) << col)
bph.touchMap[row-1] |= uint16(1) << col
} else {
// Deletion is propagated upwards
bph.touchMap[row-1] |= (uint16(1) << col)
bph.afterMap[row-1] &^= (uint16(1) << col)
bph.touchMap[row-1] |= uint16(1) << col
bph.afterMap[row-1] &^= uint16(1) << col
}
}
upBinaryCell.hl = 0
Expand Down Expand Up @@ -1060,7 +1059,7 @@ func (bph *BinPatriciaHashed) fold() (branchData BranchData, updateKey []byte, e
bph.rootTouched = true
} else {
// Modifiction is propagated upwards
bph.touchMap[row-1] |= (uint16(1) << col)
bph.touchMap[row-1] |= uint16(1) << col
}
}
nibble := bits.TrailingZeros16(bph.afterMap[row])
Expand Down Expand Up @@ -1089,7 +1088,7 @@ func (bph *BinPatriciaHashed) fold() (branchData BranchData, updateKey []byte, e
bph.rootTouched = true
} else {
// Modifiction is propagated upwards
bph.touchMap[row-1] |= (uint16(1) << col)
bph.touchMap[row-1] |= uint16(1) << col
}
}
bitmap := bph.touchMap[row] & bph.afterMap[row]
Expand Down Expand Up @@ -1212,8 +1211,8 @@ func (bph *BinPatriciaHashed) deleteBinaryCell(hashedKey []byte) {
cell = &bph.grid[row][col]
if bph.afterMap[row]&(uint16(1)<<col) != 0 {
// Prevent "spurios deletions", i.e. deletion of absent items
bph.touchMap[row] |= (uint16(1) << col)
bph.afterMap[row] &^= (uint16(1) << col)
bph.touchMap[row] |= uint16(1) << col
bph.afterMap[row] &^= uint16(1) << col
if bph.trace {
fmt.Printf("deleteBinaryCell setting (%d, %x)\n", row, col)
}
Expand All @@ -1240,8 +1239,8 @@ func (bph *BinPatriciaHashed) updateBinaryCell(plainKey, hashedKey []byte) *Bina
depth = bph.depths[row]
col = int(hashedKey[bph.currentKeyLen])
cell = &bph.grid[row][col]
bph.touchMap[row] |= (uint16(1) << col)
bph.afterMap[row] |= (uint16(1) << col)
bph.touchMap[row] |= uint16(1) << col
bph.afterMap[row] |= uint16(1) << col
if bph.trace {
fmt.Printf("updateBinaryCell setting (%d, %x), depth=%d\n", row, col, depth)
}
Expand Down
5 changes: 2 additions & 3 deletions commitment/hex_patricia_hashed.go
Original file line number Diff line number Diff line change
Expand Up @@ -780,10 +780,9 @@ func (hph *HexPatriciaHashed) needUnfolding(hashedKey []byte) int {
if cell.hl == 0 {
// cell is empty, no need to unfold further
return 0
} else {
// unfold branch node
return 1
}
// unfold branch node
return 1
}
cpl := commonPrefixLen(hashedKey[depth:], cell.downHashedKey[:cell.downHashedLen-1])
if hph.trace {
Expand Down
9 changes: 8 additions & 1 deletion common/background/progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,14 @@ func (s *ProgressSet) String() string {
var sb strings.Builder
var i int
s.list.Scan(func(_ int, p *Progress) bool {
sb.WriteString(fmt.Sprintf("%s=%d%%", *p.Name.Load(), p.percent()))
if p == nil {
return true
}
namePtr := p.Name.Load()
if namePtr == nil {
return true
}
sb.WriteString(fmt.Sprintf("%s=%d%%", *namePtr, p.percent()))
i++
if i != s.list.Len() {
sb.WriteString(", ")
Expand Down
Loading

0 comments on commit e6c0ae3

Please sign in to comment.