Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge platon #28

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/unit_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.16
go-version: ^1.16.5
id: go

- name: Check out code into the Go module directory
Expand All @@ -35,7 +35,7 @@ jobs:
run: make alaya

- name: Test
run: go test -tags=test -covermode=count -coverprofile=coverage.txt `go list ./... | grep -v 'mobile'`
run: go test -tags=test -covermode=count -coverprofile=coverage.txt `go list ./...| grep -v 'mobile'`

- name: Upload coverage report
uses: codecov/codecov-action@v1
Expand Down
4 changes: 0 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ alaya:
@echo "Done building."
@echo "Run \"$(GOBIN)/alaya\" to launch alaya."

fix-cbft-test:
build/cbft_test.sh
@echo "Done fix."

alaya-with-mpc:
build/build_deps.sh
$(GORUN) build/ci.go install -mpc on ./cmd/alaya
Expand Down
2 changes: 1 addition & 1 deletion cmd/alaya/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func runPlatON(t *testing.T, args ...string) *testplaton {
if tt.Datadir == "" {
tt.Datadir = tmpdir(t)
tt.Cleanup = func() { os.RemoveAll(tt.Datadir) }
args = append([]string{"-datadir", tt.Datadir}, args...)
args = append([]string{"--datadir", tt.Datadir}, args...)
// Remove the temporary datadir if something fails below.
defer func() {
if t.Failed() {
Expand Down
2 changes: 0 additions & 2 deletions core/block_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,8 @@ func CalcGasLimit(parent *types.Block, gasFloor /*, gasCeil*/ uint64) uint64 {
gasFloor = gasCeil
}

// contrib = (parentGasUsed * 3 / 2) / 256
contrib := (parent.GasUsed() + parent.GasUsed()/2) / params.GasLimitBoundDivisor

// decay = parentGasLimit / 256 -1
decay := parent.GasLimit()/params.GasLimitBoundDivisor - 1

/*
Expand Down
1 change: 0 additions & 1 deletion core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,6 @@ func (bc *BlockChain) GetBlock(hash common.Hash, number uint64) *types.Block {
return bc.getBlock(hash, number)
}

// modified by PlatON
func (bc *BlockChain) getBlock(hash common.Hash, number uint64) *types.Block {
// Short circuit if the block's already in the cache, retrieve otherwise
if block, ok := bc.blockCache.Get(hash); ok {
Expand Down
4 changes: 0 additions & 4 deletions core/blockchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package core

import (
"encoding/json"
"fmt"
"math/big"
"testing"
Expand Down Expand Up @@ -268,9 +267,6 @@ func testReorg(t *testing.T, first, second []int64, td int64, full bool) {
if full {
prev := blockchain.engine.CurrentBlock()

b, _ := json.Marshal(prev)
fmt.Println("current block", string(b))

for block := blockchain.engine.GetBlockByHash(prev.ParentHash()); block != nil; prev, block = block, blockchain.engine.GetBlockByHash(block.ParentHash()) {

//for block := blockchain.GetBlockByNumber(blockchain.CurrentBlock().NumberU64() - 1); block.NumberU64() != 0; prev, block = block, blockchain.GetBlockByNumber(block.NumberU64()-1) {
Expand Down
3 changes: 1 addition & 2 deletions core/tx_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,6 @@ type TxPool struct {
gasPrice *big.Int
txFeed event.Feed
scope event.SubscriptionScope
// modified by PlatON

signer types.Signer
mu sync.RWMutex
Expand Down Expand Up @@ -452,7 +451,6 @@ func (pool *TxPool) loop() {
}
}

// added by PlatON
func (pool *TxPool) Reset(newBlock *types.Block) {
startTime := time.Now()
if pool == nil {
Expand Down Expand Up @@ -1032,6 +1030,7 @@ func (pool *TxPool) addTxs(txs []*types.Transaction, local, sync bool) []error {
nilSlot++
}
errs[nilSlot] = err
nilSlot++
}

if request {
Expand Down
4 changes: 1 addition & 3 deletions core/tx_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ func newTestTxPool(config TxPoolConfig, chainconfig *params.ChainConfig) *TxPool
queue: make(map[common.Address]*txList),
beats: make(map[common.Address]time.Time),
all: newTxLookup(),
// modified by PlatON
// chainHeadCh: make(chan ChainHeadEvent, chainHeadChanSize),
exitCh: make(chan struct{}),
gasPrice: new(big.Int).SetUint64(config.PriceLimit),
Expand Down Expand Up @@ -142,7 +141,6 @@ func newTestTxPool(config TxPoolConfig, chainconfig *params.ChainConfig) *TxPool
}
}
// Subscribe events from blockchain
// modified by PlatON
//pool.chainHeadSub = pool.chain.SubscribeChainHeadEvent(pool.chainHeadCh)

// Start the event loop and return
Expand Down Expand Up @@ -924,7 +922,7 @@ func TestTransactionQueueTimeLimitingNoLocals(t *testing.T) {
func testTransactionQueueTimeLimiting(t *testing.T, nolocals bool) {
// Reduce the eviction interval to a testable amount
defer func(old time.Duration) { evictionInterval = old }(evictionInterval)
evictionInterval = time.Second
evictionInterval = time.Millisecond * 100

// Create the pool to test the non-expiration enforcement
config := testTxPoolConfig
Expand Down
18 changes: 13 additions & 5 deletions crypto/secp256k1/secp256.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,19 @@ package secp256k1
/*
#cgo CFLAGS: -I./libsecp256k1
#cgo CFLAGS: -I./libsecp256k1/src/

#ifdef __SIZEOF_INT128__
# define HAVE___INT128
# define USE_FIELD_5X52
# define USE_SCALAR_4X64
#else
# define USE_FIELD_10X26
# define USE_SCALAR_8X32
#endif

#define USE_ENDOMORPHISM
#define USE_NUM_NONE
#define USE_FIELD_10X26
#define USE_FIELD_INV_BUILTIN
#define USE_SCALAR_8X32
#define USE_SCALAR_INV_BUILTIN
#define NDEBUG
#include "./libsecp256k1/src/secp256k1.c"
Expand All @@ -26,9 +35,9 @@ import "C"

import (
"errors"
"github.com/AlayaNetwork/Alaya-Go/common/math"
"math/big"
"unsafe"
"github.com/AlayaNetwork/Alaya-Go/common/math"
)

var context *C.secp256k1_context
Expand Down Expand Up @@ -173,6 +182,5 @@ func PubkeyNotInfinity(x, y *big.Int) bool {
math.ReadBits(y, point[32:])
pointPtr := (*C.uchar)(unsafe.Pointer(&point[0]))
res := C.secp256k1_pubkey_is_infinity(context, pointPtr)
return res ==0
return res == 0
}

4 changes: 2 additions & 2 deletions eth/api_tps_cal.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ func AnalyzeStressTest(configPaths []string, output string, t int) error {
latencyCell := row.AddCell()
latencyCell.Value = strconv.FormatInt(d[1], 10)
tpsCell := row.AddCell()
tpsCell.Value = strconv.FormatInt(d[2], 10)
tpsCell.SetInt64(d[2])
ttfCell := row.AddCell()
ttfCell.Value = strconv.FormatInt(d[3], 10)
ttfCell.SetInt64(d[3])
if i == 0 {
totalReceive := row.AddCell()
totalReceive.Value = strconv.FormatInt(int64(total), 10)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/AlayaNetwork/Alaya-Go

go 1.13
go 1.14

require (
github.com/Azure/azure-pipeline-go v0.0.0-20180607212504-7571e8eb0876 // indirect
Expand Down
46 changes: 34 additions & 12 deletions internal/cmdtest/test_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import (
"regexp"
"strings"
"sync"
"sync/atomic"
"syscall"
"testing"
"text/template"
"time"
Expand All @@ -50,12 +52,17 @@ type TestCmd struct {
stdout *bufio.Reader
stdin io.WriteCloser
stderr *testlogger
// Err will contain the process exit error or interrupt signal error
Err error
}

var id int32

// Run exec's the current binary using name as argv[0] which will trigger the
// reexec init function for that name (e.g. "alaya-test" in cmd/alaya/run_test.go)
func (tt *TestCmd) Run(name string, args ...string) {
tt.stderr = &testlogger{t: tt.T}
id := atomic.AddInt32(&id, 1)
tt.stderr = &testlogger{t: tt.T, name: fmt.Sprintf("%d", id)}
tt.cmd = &exec.Cmd{
Path: reexec.Self(),
Args: append([]string{name}, args...),
Expand All @@ -74,7 +81,7 @@ func (tt *TestCmd) Run(name string, args ...string) {
}
}

// InputLine writes the given text to the childs stdin.
// InputLine writes the given text to the child's stdin.
// This method can also be called from an expect template, e.g.:
//
// alaya.expect(`Passphrase: {{.InputLine "password"}}`)
Expand Down Expand Up @@ -109,7 +116,6 @@ func (tt *TestCmd) Expect(tplsource string) {
want := bytes.TrimPrefix(wantbuf.Bytes(), []byte("\n"))

if err := tt.matchExactOutput(want); err != nil {
tt.Log(tt.StderrText())
tt.Fatal(err)
}
tt.Logf("Matched stdout text:\n%s", want)
Expand All @@ -121,6 +127,7 @@ func (tt *TestCmd) matchExactOutput(want []byte) error {
n := 0
tt.withKillTimeout(func() { n, _ = io.ReadFull(tt.stdout, buf) })
buf = buf[:n]
tt.Log(string(buf))
if n < len(want) || !bytes.Equal(buf, want) {

// Grab any additional buffered output in case of mismatch
Expand All @@ -131,12 +138,12 @@ func (tt *TestCmd) matchExactOutput(want []byte) error {

for i := 0; i < n; i++ {
if want[i] != buf[i] {
return fmt.Errorf("Output mismatch at ◊:\n---------------- (stdout text)\n%s◊%s\n---------------- (expected text)\n%s",
return fmt.Errorf("output mismatch at ◊:\n---------------- (stdout text)\n%s◊%s\n---------------- (expected text)\n%s",
buf[:i], buf[i:n], want)
}
}
if n < len(want) {
return fmt.Errorf("Not enough output, got until ◊:\n---------------- (stdout text)\n%s\n---------------- (expected text)\n%s◊%s",
return fmt.Errorf("not enough output, got until ◊:\n---------------- (stdout text)\n%s\n---------------- (expected text)\n%s◊%s",
buf, want[:n], want[n:])
}
}
Expand Down Expand Up @@ -189,11 +196,25 @@ func (tt *TestCmd) ExpectExit() {
}

func (tt *TestCmd) WaitExit() {
tt.cmd.Wait()
tt.Err = tt.cmd.Wait()
}

func (tt *TestCmd) Interrupt() {
tt.cmd.Process.Signal(os.Interrupt)
tt.Err = tt.cmd.Process.Signal(os.Interrupt)
}

// ExitStatus exposes the process' OS exit code
// It will only return a valid value after the process has finished.
func (tt *TestCmd) ExitStatus() int {
if tt.Err != nil {
exitErr := tt.Err.(*exec.ExitError)
if exitErr != nil {
if status, ok := exitErr.Sys().(syscall.WaitStatus); ok {
return status.ExitStatus()
}
}
}
return 0
}

// StderrText returns any stderr output written so far.
Expand All @@ -217,7 +238,7 @@ func (tt *TestCmd) Kill() {
}

func (tt *TestCmd) withKillTimeout(fn func()) {
timeout := time.AfterFunc(5*time.Second, func() {
timeout := time.AfterFunc(30*time.Second, func() {
tt.Log("killing the child process (timeout)")
tt.Kill()
})
Expand All @@ -228,16 +249,17 @@ func (tt *TestCmd) withKillTimeout(fn func()) {
// testlogger logs all written lines via t.Log and also
// collects them for later inspection.
type testlogger struct {
t *testing.T
mu sync.Mutex
buf bytes.Buffer
t *testing.T
mu sync.Mutex
buf bytes.Buffer
name string
}

func (tl *testlogger) Write(b []byte) (n int, err error) {
lines := bytes.Split(b, []byte("\n"))
for _, line := range lines {
if len(line) > 0 {
tl.t.Logf("(stderr) %s", line)
tl.t.Logf("(stderr:%v) %s", tl.name, line)
}
}
tl.mu.Lock()
Expand Down
1 change: 1 addition & 0 deletions x/plugin/restricting_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,7 @@ func (rp *RestrictingPlugin) releaseRestricting(epoch uint64, state xcom.StateDB
rp.log.Debug("Call releaseRestricting: begin to release record", "index", index, "account", account,
"restrictInfo", restrictInfo, "releaseAmount", releaseAmount)

//if NeedRelease>0,CachePlanAmount = AdvanceAmount
if restrictInfo.NeedRelease.Cmp(common.Big0) > 0 {
if gov.Gte0140VersionState(state) {
restrictInfo.NeedRelease.Add(restrictInfo.NeedRelease, releaseAmount)
Expand Down