Skip to content
This repository has been archived by the owner on Mar 21, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1827 from Bytom/dev
Browse files Browse the repository at this point in the history
Merge dev to prod
  • Loading branch information
Paladz authored Feb 5, 2020
2 parents 5dd8839 + 9de7356 commit e49a099
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 9 deletions.
3 changes: 3 additions & 0 deletions consensus/general.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ var MainNetParams = Params{
{270000, bc.NewHash([32]byte{0x9d, 0x6f, 0xcc, 0xd8, 0xb8, 0xe4, 0x8c, 0x17, 0x52, 0x9a, 0xe6, 0x1b, 0x40, 0x60, 0xe0, 0xe3, 0x6d, 0x1e, 0x89, 0xc0, 0x26, 0xdf, 0x1c, 0x28, 0x18, 0x0d, 0x29, 0x0c, 0x9b, 0x15, 0xcc, 0x97})},
{300000, bc.NewHash([32]byte{0xa2, 0x85, 0x84, 0x6c, 0xe0, 0x3e, 0x1d, 0x68, 0x98, 0x7d, 0x93, 0x21, 0xea, 0xcc, 0x1d, 0x07, 0x88, 0xd1, 0x4c, 0x77, 0xa3, 0xd7, 0x55, 0x8a, 0x2b, 0x4a, 0xf7, 0x4d, 0x50, 0x14, 0x53, 0x5d})},
{320000, bc.NewHash([32]byte{0xc6, 0xe7, 0x91, 0x6f, 0xcb, 0x7a, 0x42, 0x5d, 0xd6, 0x22, 0xef, 0x5d, 0x6a, 0x5c, 0xc1, 0x91, 0xa9, 0xd9, 0x06, 0x44, 0xcf, 0x36, 0x43, 0x55, 0xfe, 0x45, 0xaf, 0x24, 0x07, 0x31, 0x23, 0xc6})},
{350000, bc.NewHash([32]byte{0xf4, 0x88, 0x6f, 0x9a, 0x17, 0x9a, 0x1c, 0x2a, 0x43, 0x9f, 0xc5, 0xae, 0x2f, 0xe4, 0xa6, 0x33, 0x71, 0xb4, 0xcd, 0x83, 0xc5, 0x23, 0xc1, 0x14, 0xb2, 0xb0, 0xa8, 0x43, 0xf2, 0xa1, 0x4b, 0x5c})},
{380000, bc.NewHash([32]byte{0xf1, 0x00, 0x41, 0xcc, 0xea, 0xf0, 0x67, 0x98, 0x49, 0x89, 0x5f, 0xa6, 0xa0, 0x8d, 0x33, 0x04, 0x93, 0x1b, 0xf8, 0x49, 0x76, 0xe1, 0x22, 0xe3, 0xce, 0xc2, 0x6f, 0x19, 0xff, 0x4f, 0x80, 0xf1})},
},
}

Expand All @@ -158,6 +160,7 @@ var TestNetParams = Params{
{113300, bc.NewHash([32]byte{0x7a, 0x69, 0x75, 0xa5, 0xf6, 0xb6, 0x94, 0xf3, 0x94, 0xa2, 0x63, 0x91, 0x28, 0xb6, 0xab, 0x7e, 0xf9, 0x71, 0x27, 0x5a, 0xe2, 0x59, 0xd3, 0xff, 0x70, 0x6e, 0xcb, 0xd8, 0xd8, 0x30, 0x9c, 0xc4})},
{235157, bc.NewHash([32]byte{0xfa, 0x76, 0x36, 0x3e, 0x9e, 0x58, 0xea, 0xe4, 0x7d, 0x26, 0x70, 0x7e, 0xf3, 0x8b, 0xfd, 0xad, 0x1a, 0x99, 0xf7, 0x4c, 0xac, 0xc6, 0x80, 0x99, 0x58, 0x10, 0x13, 0x66, 0x4b, 0x8c, 0x39, 0x4f})},
{252383, bc.NewHash([32]byte{0xa1, 0xaa, 0xe6, 0xd9, 0x42, 0x94, 0x99, 0x7b, 0x9b, 0x71, 0x5b, 0xf5, 0x23, 0x9a, 0xee, 0x92, 0x27, 0x84, 0x4c, 0x32, 0x47, 0xf2, 0xf2, 0xd9, 0xe3, 0xd7, 0x6a, 0x2b, 0xbe, 0xc3, 0x1f, 0x50})},
{320000, bc.NewHash([32]byte{0xb5, 0x9f, 0xeb, 0x44, 0x4a, 0xfd, 0x67, 0x2a, 0x1c, 0x99, 0x8e, 0xc8, 0x48, 0xac, 0xeb, 0xfe, 0x80, 0xf6, 0x58, 0x7a, 0xf1, 0x7d, 0xea, 0xd6, 0xc7, 0xe5, 0x93, 0x3f, 0xae, 0x65, 0x88, 0xe6})},
},
}

Expand Down
16 changes: 8 additions & 8 deletions protocol/validation/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,18 @@ func ValidateBlock(b *bc.Block, parent *state.BlockNode) error {
blockGasSum := uint64(0)
coinbaseAmount := consensus.BlockSubsidy(b.BlockHeader.Height)
b.TransactionStatus = bc.NewTransactionStatus()

for i, tx := range b.Transactions {
gasStatus, err := ValidateTx(tx, b)
if !gasStatus.GasValid {
return errors.Wrapf(err, "validate of transaction %d of %d", i, len(b.Transactions))
validateResults := ValidateTxs(b.Transactions, b)
for i, validateResult := range validateResults {
if !validateResult.gasStatus.GasValid {
return errors.Wrapf(validateResult.err, "validate of transaction %d of %d", i, len(b.Transactions))
}

if err := b.TransactionStatus.SetStatus(i, err != nil); err != nil {
if err := b.TransactionStatus.SetStatus(i, validateResult.err != nil); err != nil {
return err
}
coinbaseAmount += gasStatus.BTMValue
if blockGasSum += uint64(gasStatus.GasUsed); blockGasSum > consensus.MaxBlockGas {

coinbaseAmount += validateResult.gasStatus.BTMValue
if blockGasSum += uint64(validateResult.gasStatus.GasUsed); blockGasSum > consensus.MaxBlockGas {
return errOverBlockLimit
}
}
Expand Down
63 changes: 63 additions & 0 deletions protocol/validation/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package validation
import (
"fmt"
"math"
"runtime"
"sync"

"github.com/bytom/bytom/consensus"
"github.com/bytom/bytom/consensus/segwit"
Expand Down Expand Up @@ -515,3 +517,64 @@ func ValidateTx(tx *bc.Tx, block *bc.Block) (*GasState, error) {
}
return vs.gasStatus, checkValid(vs, tx.TxHeader)
}

type validateTxWork struct {
i int
tx *bc.Tx
block *bc.Block
}

// ValidateTxResult is the result of async tx validate
type ValidateTxResult struct {
i int
gasStatus *GasState
err error
}

// GetGasState return the gasStatus
func (r *ValidateTxResult) GetGasState() *GasState {
return r.gasStatus
}

// GetError return the err
func (r *ValidateTxResult) GetError() error {
return r.err
}

func validateTxWorker(workCh chan *validateTxWork, resultCh chan *ValidateTxResult, wg *sync.WaitGroup) {
for work := range workCh {
gasStatus, err := ValidateTx(work.tx, work.block)
resultCh <- &ValidateTxResult{i: work.i, gasStatus: gasStatus, err: err}
}
wg.Done()
}

// ValidateTxs validates txs in async mode
func ValidateTxs(txs []*bc.Tx, block *bc.Block) []*ValidateTxResult {
txSize := len(txs)
validateWorkerNum := runtime.NumCPU()
//init the goroutine validate worker
var wg sync.WaitGroup
workCh := make(chan *validateTxWork, txSize)
resultCh := make(chan *ValidateTxResult, txSize)
for i := 0; i <= validateWorkerNum && i < txSize; i++ {
wg.Add(1)
go validateTxWorker(workCh, resultCh, &wg)
}

//sent the works
for i, tx := range txs {
workCh <- &validateTxWork{i: i, tx: tx, block: block}
}
close(workCh)

//collect validate results
results := make([]*ValidateTxResult, txSize)
for i := 0; i < txSize; i++ {
result := <-resultCh
results[result.i] = result
}

wg.Wait()
return results
}
2 changes: 1 addition & 1 deletion version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const (

var (
// The full version string
Version = "1.0.10"
Version = "1.1.0"
// GitCommit is set with --ldflags "-X main.gitCommit=$(git rev-parse HEAD)"
GitCommit string
Status *UpdateStatus
Expand Down

0 comments on commit e49a099

Please sign in to comment.