Skip to content

Commit

Permalink
Merge branch 'dev' into hardfork/pos
Browse files Browse the repository at this point in the history
  • Loading branch information
DarianShawn committed Oct 25, 2022
2 parents b730d55 + 5e07351 commit ef866a3
Show file tree
Hide file tree
Showing 17 changed files with 589 additions and 240 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
name: Build
on: # yamllint disable-line rule:truthy
workflow_dispatch:
workflow_call:

jobs:
go_build:
name: Dogechain
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup Go environment
# uses: actions/setup-go@v3.3.0
uses: actions/setup-go@v2
with:
go-version: 1.17.x

- name: Build Dogechain
# run: go build -tags netgo -ldflags="-s -w -linkmode external -extldflags "-static" -X \"github.com/dogechain-lab/dogechain/versioning.Version=${GITHUB_REF_NAME}\" -X \"github.com/dogechain-lab/dogechain/versioning.Commit=${GITHUB_SHA}\"" && tar -czvf dogechain.tar.gz dogechain
run: go build -a -o dogechain . && tar -czvf dogechain.tar.gz dogechain
env:
CGO_ENABLED: 0
CC: gcc
CXX: g++
GOARC: amd64
GOOS: linux

- name: Extract branch name
# if: github.event_name != 'pull_request'
shell: bash
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
id: extract_branch

- name: "Upload Artifact"
uses: actions/upload-artifact@v3
with:
name: dogechain_${{ github.sha }}_${{ steps.extract_branch.outputs.branch }}
path: dogechain.tar.gz
retention-days: 7
31 changes: 31 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
name: E2E tests
on: # yamllint disable-line rule:truthy
push:
branches:
- main
- dev
pull_request:

jobs:
build:
runs-on: ubuntu-latest
# env:
# E2E_TESTS: true
# E2E_LOGS: true
# CI_VERBOSE: true
steps:
- uses: actions/checkout@v2
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.17.x
- name: Run tests
run: make test-e2e
# - name: Archive test logs
# if: always()
# uses: actions/upload-artifact@v3
# with:
# name: e2e-logs
# path: e2e-logs-*/
# retention-days: 30
29 changes: 29 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
name: Lint
on: # yamllint disable-line rule:truthy
push:
branches-ignore:
- "main"
- "dev"
tags-ignore:
- "v*"
paths:
- "**.go"
workflow_call: {}
workflow_dispatch: {}
pull_request:

jobs:
golangci_lint:
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.17.x

- name: Checkout code
uses: actions/checkout@v3

- name: Lint
uses: golangci/golangci-lint-action@v3
89 changes: 0 additions & 89 deletions .github/workflows/main.yml

This file was deleted.

29 changes: 29 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
name: Test
on: # yamllint disable-line rule:truthy
workflow_dispatch:
workflow_call:
pull_request:

jobs:
go_test:
name: Dogechain
runs-on: ubuntu-latest
steps:
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: 1.17.x

- name: Checkout Code
uses: actions/checkout@v3
with:
submodules: recursive

- name: Run Go Test
run: go test -coverprofile coverage.out -timeout 20m `go list ./... | grep -v e2e`

- name: Upload coverage file to Codecov
uses: codecov/codecov-action@v3
with:
files: coverage.out
File renamed without changes.
10 changes: 9 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,20 @@ build:

.PHONY: lint
lint:
golangci-lint run -c lint-rule.yaml
golangci-lint run -c .golangci.yml

.PHONY: test
test: build
PATH=$(shell pwd):${PATH} go test -count=1 -coverprofile coverage.out -timeout 28m ./...

.PHONY: test-e2e
test-e2e: build
# We need to build the binary with the race flag enabled
# because it will get picked up and run during e2e tests
# and the e2e tests should error out if any kind of race is found
go build -race -o artifacts/dogechain .
PATH=${PWD}/artifacts:${PATH} go test -v -timeout=30m ./e2e/...

.PHONY: generate-bsd-licenses
generate-bsd-licenses:
./generate_dependency_licenses.sh BSD-3-Clause,BSD-2-Clause > ./licenses/bsd_licenses.json
52 changes: 32 additions & 20 deletions consensus/dev/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,61 +108,73 @@ type transitionInterface interface {
}

func (d *Dev) writeTransactions(gasLimit uint64, transition transitionInterface) []*types.Transaction {
var successful []*types.Transaction
var includedTxs []*types.Transaction

d.txpool.Prepare()
// get all pending transactions once and for all
pendingTxs := d.txpool.Pending()
// get highest price transaction queue
priceTxs := types.NewTransactionsByPriceAndNonce(pendingTxs)

for {
tx := d.txpool.Pop()
tx := priceTxs.Peek()
if tx == nil {
d.logger.Debug("no more transactions")

break
}

if tx.ExceedsBlockGasLimit(gasLimit) {
// The address is punished. For current loop, it would not include its transactions any more.
d.txpool.Drop(tx)
priceTxs.Pop()

continue
}

if err := transition.Write(tx); err != nil {
d.logger.Debug("write transaction failed", "hash", tx.Hash(), "from", tx.From,
"nonce", tx.Nonce, "err", err)

//nolint:errorlint
if _, ok := err.(*state.GasLimitReachedTransitionApplicationError); ok {
// Ignore those out-of-gas transaction whose gas limit too large
} else if _, ok := err.(*state.AllGasUsedError); ok {
if _, ok := err.(*state.AllGasUsedError); ok {
// no more transaction could be packed
d.logger.Debug("Not enough gas for further transactions")

break
} else if _, ok := err.(*state.GasLimitReachedTransitionApplicationError); ok {
// Ignore transaction when the free gas not enough
d.logger.Debug("Gas limit exceeded for current block", "from", tx.From)
priceTxs.Pop()
} else if nonceErr, ok := err.(*state.NonceTooLowError); ok {
// lower nonce tx, demote all promotable transactions
// low nonce tx, should reset accounts once done
d.logger.Warn("write transaction nonce too low",
"hash", tx.Hash(), "from", tx.From, "nonce", tx.Nonce)
// skip the address, whose txs should be reset first.
d.txpool.DemoteAllPromoted(tx, nonceErr.CorrectNonce)
d.logger.Error("write transaction nonce too low", "hash", tx.Hash(), "from", tx.From,
"nonce", tx.Nonce, "err", err)
priceTxs.Pop()
} else if nonceErr, ok := err.(*state.NonceTooHighError); ok {
// higher nonce tx, demote all promotable transactions
// high nonce tx, should reset accounts once done
d.logger.Error("write miss some transactions with higher nonce",
"hash", tx.Hash(), "from", tx.From, "nonce", tx.Nonce)
d.txpool.DemoteAllPromoted(tx, nonceErr.CorrectNonce)
d.logger.Error("write miss some transactions with higher nonce", tx.Hash(), "from", tx.From,
"nonce", tx.Nonce, "err", err)
priceTxs.Pop()
} else {
// no matter what kind of failure, drop is reasonable for not executed it yet
d.logger.Debug("write not executed transaction failed",
"hash", tx.Hash(), "from", tx.From, "nonce", tx.Nonce, "err", err)
d.txpool.Drop(tx)
priceTxs.Pop()
}

continue
}

// no errors, pop the tx from the pool
d.txpool.RemoveExecuted(tx)
// no errors, go on
priceTxs.Shift()

successful = append(successful, tx)
includedTxs = append(includedTxs, tx)
}

d.logger.Info("picked out txns from pool", "num", len(successful), "remaining", d.txpool.Length())
d.logger.Info("picked out txns from pool", "num", len(includedTxs))

return successful
return includedTxs
}

// writeNewBLock generates a new block based on transactions from the pool,
Expand Down
Loading

0 comments on commit ef866a3

Please sign in to comment.