diff --git a/.github/workflows/unit_test.yml b/.github/workflows/unit_test.yml index a386698ab9..a74c357d47 100644 --- a/.github/workflows/unit_test.yml +++ b/.github/workflows/unit_test.yml @@ -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 @@ -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 diff --git a/Makefile b/Makefile index 1b6aa61636..6cda9745cc 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/cmd/alaya/run_test.go b/cmd/alaya/run_test.go index cde4409767..be863be885 100644 --- a/cmd/alaya/run_test.go +++ b/cmd/alaya/run_test.go @@ -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() { diff --git a/core/block_validator.go b/core/block_validator.go index 83effc5be9..d6b6092029 100644 --- a/core/block_validator.go +++ b/core/block_validator.go @@ -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 /* diff --git a/core/blockchain.go b/core/blockchain.go index 95039d5659..2986eadc5a 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -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 { diff --git a/core/blockchain_test.go b/core/blockchain_test.go index 9e02df17b4..019c13fc6d 100644 --- a/core/blockchain_test.go +++ b/core/blockchain_test.go @@ -17,7 +17,6 @@ package core import ( - "encoding/json" "fmt" "math/big" "testing" @@ -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) { diff --git a/core/tx_pool.go b/core/tx_pool.go index e21a3c1fc2..6a8856fee8 100644 --- a/core/tx_pool.go +++ b/core/tx_pool.go @@ -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 @@ -452,7 +451,6 @@ func (pool *TxPool) loop() { } } -// added by PlatON func (pool *TxPool) Reset(newBlock *types.Block) { startTime := time.Now() if pool == nil { @@ -1032,6 +1030,7 @@ func (pool *TxPool) addTxs(txs []*types.Transaction, local, sync bool) []error { nilSlot++ } errs[nilSlot] = err + nilSlot++ } if request { diff --git a/core/tx_pool_test.go b/core/tx_pool_test.go index 396907115d..2ebad1dbf2 100644 --- a/core/tx_pool_test.go +++ b/core/tx_pool_test.go @@ -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), @@ -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 @@ -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 diff --git a/crypto/secp256k1/secp256.go b/crypto/secp256k1/secp256.go index cfcff989f5..765ff3dae2 100644 --- a/crypto/secp256k1/secp256.go +++ b/crypto/secp256k1/secp256.go @@ -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" @@ -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 @@ -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 } - diff --git a/eth/api_tps_cal.go b/eth/api_tps_cal.go index 65469706dc..3797b26e9c 100644 --- a/eth/api_tps_cal.go +++ b/eth/api_tps_cal.go @@ -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) diff --git a/go.mod b/go.mod index 06e3559ce6..3b8edbb26b 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/internal/cmdtest/test_cmd.go b/internal/cmdtest/test_cmd.go index 50e5040c41..03ea1da48b 100644 --- a/internal/cmdtest/test_cmd.go +++ b/internal/cmdtest/test_cmd.go @@ -27,6 +27,8 @@ import ( "regexp" "strings" "sync" + "sync/atomic" + "syscall" "testing" "text/template" "time" @@ -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...), @@ -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"}}`) @@ -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) @@ -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 @@ -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:]) } } @@ -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. @@ -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() }) @@ -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() diff --git a/x/plugin/restricting_plugin.go b/x/plugin/restricting_plugin.go index 356b324ffb..885410f2fd 100644 --- a/x/plugin/restricting_plugin.go +++ b/x/plugin/restricting_plugin.go @@ -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)