Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
69dae34
Merge pull request #266 from CovenantSQL/develop
leventeliu Feb 26, 2019
2cc39a8
Format logs and remove load chain method
leventeliu Feb 28, 2019
be56419
Remove head state persistence
leventeliu Mar 4, 2019
cd05207
Fix format string of errors wrap
leventeliu Mar 4, 2019
57931d4
Format logs and remove unused fields in chain
leventeliu Mar 4, 2019
6552567
Fix genesis block height
leventeliu Mar 4, 2019
b05e8c2
Format more logs
leventeliu Mar 5, 2019
9f5ab42
Add common method to create log entry context
leventeliu Mar 5, 2019
b19c65b
Skip empty blocks
leventeliu Mar 5, 2019
8eaa3f5
Merge remote-tracking branch 'origin/develop' into feature/beta_sqlch…
leventeliu Mar 5, 2019
43b3006
Add reads pool
leventeliu Mar 6, 2019
4cc255a
Minor fix for meta linter
leventeliu Mar 6, 2019
14adc2b
Refactor internal interfaces
leventeliu Mar 6, 2019
649e827
Merge remote-tracking branch 'origin/develop' into feature/beta_sqlch…
leventeliu Mar 6, 2019
a47938f
Merge pull request #274 from CovenantSQL/develop
auxten Mar 6, 2019
ece69dd
Remove unused config fields
leventeliu Mar 6, 2019
ae51b90
Merge remote-tracking branch 'origin/beta' into feature/beta_sqlchain…
leventeliu Mar 6, 2019
5739ec5
Skip compatibility test for beta branch
leventeliu Mar 6, 2019
de0c00a
Fix bug on chain startup
leventeliu Mar 7, 2019
a8c8c9f
Fix bug: billing on empty blocks
leventeliu Mar 7, 2019
95a864d
Minor fix
leventeliu Mar 7, 2019
5a98458
Add select statement for channel operator
leventeliu Mar 7, 2019
05b24c4
Minor fix
leventeliu Mar 7, 2019
e99f434
Remove obsolete billing protocol
leventeliu Mar 7, 2019
e2c1a7a
Add billing range
leventeliu Mar 7, 2019
d2a48cf
Add comment for exported method
leventeliu Mar 7, 2019
e7ba433
Merge pull request #275 from CovenantSQL/feature/beta_sqlchain_refactor
auxten Mar 13, 2019
6b51d52
Use a global leveldb instance for multiple chains
leventeliu Mar 22, 2019
a94e141
Merge pull request #289 from CovenantSQL/feature/beta_glob_leveldb
xq262144 Mar 27, 2019
f706027
Reduce meta key length using byte version database id
Mar 27, 2019
2e93401
Fix database test case using valid database id
Mar 27, 2019
cda2a61
Merge remote-tracking branch 'origin/develop' into feature/beta_upstream
leventeliu Mar 27, 2019
e470313
Fix mirror test case waiting logic bug
Mar 27, 2019
66e2b91
Merge pull request #296 from CovenantSQL/feature/beta_upstream
auxten Mar 27, 2019
988da9f
Merge branch 'beta' into bugfix/beta_chain_db_key_prefix
Mar 27, 2019
3de7a24
Merge pull request #294 from CovenantSQL/bugfix/beta_chain_db_key_prefix
leventeliu Mar 28, 2019
b7e8c56
Revert a transaction type removal
leventeliu Mar 28, 2019
f145acb
Merge pull request #297 from CovenantSQL/feature/beta_revert
leventeliu Mar 28, 2019
53f3810
Merge branch 'develop' into beta
auxten Mar 28, 2019
50c8869
Support version upgrade in update billing tx header
Mar 28, 2019
86333a4
Increase goroutine leak threshold to 150
Mar 28, 2019
5a8c774
Skip old version billing
leventeliu Mar 28, 2019
0537f6f
Increase another threshold of go routine count
Mar 28, 2019
46d4978
Merge pull request #299 from CovenantSQL/bugfix/beta_billing_header_u…
leventeliu Mar 28, 2019
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
9 changes: 9 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ old-client-compatibility:
- set -o errexit
- set -o pipefail
- set -x
- commit=$(git rev-parse --short HEAD)
- branch=$(git branch -rv |grep $commit | awk '{print $1}')
- if [[ $branch =~ "/beta_" ]]; then exit 0; fi
- make clean
- cp ${BIN_CACHE}/* bin/
- ./test/compatibility/specific_old.sh client
Expand All @@ -79,6 +82,9 @@ old-bp-compatibility:
- set -o errexit
- set -o pipefail
- set -x
- commit=$(git rev-parse --short HEAD)
- branch=$(git branch -rv |grep $commit | awk '{print $1}')
- if [[ $branch =~ "/beta_" ]]; then exit 0; fi
- make clean
- cp ${BIN_CACHE}/* bin/
- ./test/compatibility/specific_old.sh bp
Expand All @@ -89,6 +95,9 @@ old-miner-compatibility:
- set -o errexit
- set -o pipefail
- set -x
- commit=$(git rev-parse --short HEAD)
- branch=$(git branch -rv |grep $commit | awk '{print $1}')
- if [[ $branch =~ "/beta_" ]]; then exit 0; fi
- make clean
- cp ${BIN_CACHE}/* bin/
- ./test/compatibility/specific_old.sh miner
Expand Down
8 changes: 4 additions & 4 deletions alltest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ set -o pipefail
set -o nounset

main() {
go test -tags "$UNITTESTTAGS" -race -failfast -parallel 16 -cpu 16 -coverprofile main.cover.out $(go list ./... | grep -v CovenantSQL/api)
go test -tags "$UNITTESTTAGS" -race -failfast -parallel 16 -cpu 16 -coverpkg ./api/...,./rpc/jsonrpc -coverprofile api.cover.out ./api/...
go test -tags "${UNITTESTTAGS:-}" -race -failfast -parallel 16 -cpu 16 -coverprofile main.cover.out $(go list ./... | grep -v CovenantSQL/api)
go test -tags "${UNITTESTTAGS:-}" -race -failfast -parallel 16 -cpu 16 -coverpkg ./api/...,./rpc/jsonrpc -coverprofile api.cover.out ./api/...

set -x
gocovmerge main.cover.out api.cover.out $(find cmd -name "*.cover.out") | grep -F -v '_gen.go' > coverage.txt && rm -f *.cover.out
bash <(curl -s https://codecov.io/bash)

# some benchmarks
go test -tags "$UNITTESTTAGS" -bench=^BenchmarkPersistentCaller_Call$ -run ^$ ./rpc/
go test -tags "${UNITTESTTAGS:-}" -bench=^BenchmarkPersistentCaller_Call$ -run ^$ ./rpc/
bash cleanupDB.sh || true
go test -tags "$UNITTESTTAGS" -bench=^BenchmarkMiner$ -benchtime=5s -run ^$ ./cmd/cql-minerd/ -bench-miner-count=2
go test -tags "${UNITTESTTAGS:-}" -bench=^BenchmarkMiner$ -benchtime=5s -run ^$ ./cmd/cql-minerd/ -bench-miner-count=2
bash cleanupDB.sh || true
}

Expand Down
2 changes: 2 additions & 0 deletions blockproducer/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ var (
ErrUnknownTransactionType = errors.New("unknown transaction type")
// ErrInvalidSender indicates that tx.Signee != tx.Sender.
ErrInvalidSender = errors.New("invalid sender")
// ErrInvalidRange indicates that the billing range is invalid.
ErrInvalidRange = errors.New("invalid billing range")
// ErrNoSuchMiner indicates that this miner does not exist or register.
ErrNoSuchMiner = errors.New("no such miner")
// ErrNoEnoughMiner indicates that there is not enough miners
Expand Down
6 changes: 2 additions & 4 deletions blockproducer/interfaces/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ func FromBytes(b []byte) TransactionType {
}

const (
// TransactionTypeBilling defines billing transaction type.
TransactionTypeBilling TransactionType = iota
// TransactionTypeDeprecated is a deprecated transaction type, do NOT use it.
TransactionTypeDeprecated TransactionType = iota
// TransactionTypeTransfer defines transfer transaction type.
TransactionTypeTransfer
// TransactionTypeCreateAccount defines account creation transaction type.
Expand Down Expand Up @@ -78,8 +78,6 @@ const (

func (t TransactionType) String() string {
switch t {
case TransactionTypeBilling:
return "Billing"
case TransactionTypeTransfer:
return "Transfer"
case TransactionTypeCreateAccount:
Expand Down
2 changes: 1 addition & 1 deletion blockproducer/interfaces/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestTypes(t *testing.T) {
}
})
Convey("test string", t, func() {
for i := TransactionTypeBilling; i != TransactionTypeNumber+1; i++ {
for i := TransactionTypeTransfer; i != TransactionTypeNumber+1; i++ {
So(i.String(), ShouldNotBeEmpty)
}
})
Expand Down
32 changes: 16 additions & 16 deletions blockproducer/interfaces/transaction_wrapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (e *TestTransactionEncode) Msgsize() int {
}

func init() {
pi.RegisterTransaction(pi.TransactionTypeBilling, (*TestTransactionEncode)(nil))
pi.RegisterTransaction(pi.TransactionTypeTransfer, (*TestTransactionEncode)(nil))
}

func TestTransactionWrapper(t *testing.T) {
Expand All @@ -81,13 +81,13 @@ func TestTransactionWrapper(t *testing.T) {

// encode test
e := &TestTransactionEncode{}
e.SetTransactionType(pi.TransactionTypeBilling)
e.SetTransactionType(pi.TransactionTypeTransfer)
buf, err = utils.EncodeMsgPack(e)
So(err, ShouldBeNil)
var v2 pi.Transaction
err = utils.DecodeMsgPack(buf.Bytes(), &v2)
So(err, ShouldBeNil)
So(v2.GetTransactionType(), ShouldEqual, pi.TransactionTypeBilling)
So(v2.GetTransactionType(), ShouldEqual, pi.TransactionTypeTransfer)

// encode with wrapper test
e2 := pi.WrapTransaction(e)
Expand All @@ -96,14 +96,14 @@ func TestTransactionWrapper(t *testing.T) {
var v3 pi.Transaction
err = utils.DecodeMsgPack(buf.Bytes(), &v3)
So(err, ShouldBeNil)
So(v3.GetTransactionType(), ShouldEqual, pi.TransactionTypeBilling)
So(v3.GetTransactionType(), ShouldEqual, pi.TransactionTypeTransfer)
tw, ok := v3.(*pi.TransactionWrapper)
So(ok, ShouldBeTrue)
So(tw.Unwrap().GetTransactionType(), ShouldEqual, pi.TransactionTypeBilling)
So(tw.Unwrap().GetTransactionType(), ShouldEqual, pi.TransactionTypeTransfer)

// test encode non-existence type
e3 := &TestTransactionEncode{}
e3.SetTransactionType(pi.TransactionTypeTransfer)
e3.SetTransactionType(pi.TransactionTypeCreateAccount)
buf, err = utils.EncodeMsgPack(e3)
So(err, ShouldBeNil)
var v4 pi.Transaction
Expand Down Expand Up @@ -132,21 +132,21 @@ func TestTransactionWrapper(t *testing.T) {
So(err, ShouldNotBeNil)

// test invalid decode, nil payload
buf, err = utils.EncodeMsgPack([]interface{}{pi.TransactionTypeBilling, nil})
buf, err = utils.EncodeMsgPack([]interface{}{pi.TransactionTypeTransfer, nil})
So(err, ShouldBeNil)
var v8 pi.Transaction
err = utils.DecodeMsgPack(buf.Bytes(), &v8)
So(err, ShouldNotBeNil)

// test invalid decode, invalid payload container type
buf, err = utils.EncodeMsgPack([]interface{}{pi.TransactionTypeBilling, []uint64{}})
buf, err = utils.EncodeMsgPack([]interface{}{pi.TransactionTypeTransfer, []uint64{}})
So(err, ShouldBeNil)
var v9 pi.Transaction
err = utils.DecodeMsgPack(buf.Bytes(), &v9)
So(err, ShouldNotBeNil)

// extra payload
buf, err = utils.EncodeMsgPack([]interface{}{pi.TransactionTypeBilling, e, 1, 2})
buf, err = utils.EncodeMsgPack([]interface{}{pi.TransactionTypeTransfer, e, 1, 2})
So(err, ShouldBeNil)
var v10 pi.Transaction
err = utils.DecodeMsgPack(buf.Bytes(), &v10)
Expand Down Expand Up @@ -174,22 +174,22 @@ func TestTransactionWrapper(t *testing.T) {
So(err, ShouldNotBeNil)

// test tx data
buf, err = utils.EncodeMsgPack(map[string]interface{}{"TxType": pi.TransactionTypeBilling, "TestField": 1})
buf, err = utils.EncodeMsgPack(map[string]interface{}{"TxType": pi.TransactionTypeTransfer, "TestField": 1})
So(err, ShouldBeNil)
var v14 pi.Transaction
err = utils.DecodeMsgPack(buf.Bytes(), &v14)
So(err, ShouldBeNil)

// test invalid tx data
buf, err = utils.EncodeMsgPack(map[string]interface{}{"TxType": pi.TransactionTypeBilling, "TestField": "happy"})
buf, err = utils.EncodeMsgPack(map[string]interface{}{"TxType": pi.TransactionTypeTransfer, "TestField": "happy"})
So(err, ShouldBeNil)
var v15 pi.Transaction
err = utils.DecodeMsgPack(buf.Bytes(), &v15)
So(err, ShouldNotBeNil)

// test json marshal and unmarshal
v16 := &TestTransactionEncode{TestField: 10}
v16.SetTransactionType(pi.TransactionTypeBilling)
v16.SetTransactionType(pi.TransactionTypeTransfer)
var v17 pi.Transaction = v16
var jsonData []byte
jsonData, err = json.Marshal(v17)
Expand All @@ -200,17 +200,17 @@ func TestTransactionWrapper(t *testing.T) {
err = json.Unmarshal(jsonData, &v18)
So(err, ShouldBeNil)
So(v18.(*pi.TransactionWrapper).Unwrap(), ShouldNotBeNil)
So(v18.GetTransactionType(), ShouldEqual, pi.TransactionTypeBilling)
So(v18.GetTransactionType(), ShouldEqual, pi.TransactionTypeTransfer)
So(v18.(*pi.TransactionWrapper).Unwrap().(*TestTransactionEncode).TestField, ShouldEqual, 10)

jsonData, err = json.Marshal(v18)
So(string(jsonData), ShouldContainSubstring, "TestField")

v18.(*pi.TransactionWrapper).Transaction = nil
jsonData = []byte(`{"TxType": 0, "TestField": 11}`)
jsonData = []byte(`{"TxType": 1, "TestField": 11}`)
err = json.Unmarshal(jsonData, &v18)
So(err, ShouldBeNil)
So(v18.GetTransactionType(), ShouldEqual, pi.TransactionTypeBilling)
So(v18.GetTransactionType(), ShouldEqual, pi.TransactionTypeTransfer)
So(v18.(*pi.TransactionWrapper).Unwrap().(*TestTransactionEncode).TestField, ShouldEqual, 11)

// unmarshal fail cases
Expand All @@ -225,7 +225,7 @@ func TestTransactionWrapper(t *testing.T) {
So(err, ShouldNotBeNil)

v18.(*pi.TransactionWrapper).Transaction = nil
jsonData = []byte(fmt.Sprintf(`{"TxType": %d, "TestField": 11}`, pi.TransactionTypeTransfer))
jsonData = []byte(fmt.Sprintf(`{"TxType": %d, "TestField": 11}`, pi.TransactionTypeCreateAccount))
err = json.Unmarshal(jsonData, &v18)
So(err, ShouldNotBeNil)
})
Expand Down
25 changes: 8 additions & 17 deletions blockproducer/metastate.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,21 +509,6 @@ func (s *metaState) increaseNonce(addr proto.AccountAddress) (err error) {
return
}

func (s *metaState) applyBilling(tx *types.Billing) (err error) {
for i, v := range tx.Receivers {
// Create empty receiver account if not found
s.loadOrStoreAccountObject(*v, &types.Account{Address: *v})

if err = s.increaseAccountCovenantBalance(*v, tx.Fees[i]); err != nil {
return
}
if err = s.increaseAccountStableBalance(*v, tx.Rewards[i]); err != nil {
return
}
}
return
}

func (s *metaState) updateProviderList(tx *types.ProvideService) (err error) {
sender, err := crypto.PubKeyHash(tx.Signee)
if err != nil {
Expand Down Expand Up @@ -915,6 +900,13 @@ func (s *metaState) updateBilling(tx *types.UpdateBilling) (err error) {
err = errors.Wrap(ErrDatabaseNotFound, "update billing failed")
return
}

if tx.Version > 0 && (tx.Range.From >= tx.Range.To || newProfile.LastUpdatedHeight != tx.Range.From) {
err = errors.Wrapf(ErrInvalidRange,
"update billing within range %d:(%d, %d]",
newProfile.LastUpdatedHeight, tx.Range.From, tx.Range.To)
return
}
log.Debugf("update billing addr: %s, user: %d, tx: %v", tx.GetAccountAddress(), len(tx.Users), tx)

if newProfile.GasPrice == 0 {
Expand Down Expand Up @@ -988,6 +980,7 @@ func (s *metaState) updateBilling(tx *types.UpdateBilling) (err error) {
}
}
}
newProfile.LastUpdatedHeight = tx.Range.To
s.dirty.databases[tx.Receiver.DatabaseID()] = newProfile
return
}
Expand Down Expand Up @@ -1128,8 +1121,6 @@ func (s *metaState) applyTransaction(tx pi.Transaction) (err error) {
err = s.transferAccountToken(t)
}
return
case *types.Billing:
err = s.applyBilling(t)
case *types.BaseAccount:
err = s.storeBaseAccount(t.Address, &t.Account)
case *types.ProvideService:
Expand Down
Loading