Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into feature/beta_merge…
Browse files Browse the repository at this point in the history
…_develop
  • Loading branch information
Qi Xiao committed Feb 18, 2019
2 parents 907b301 + 6efc92a commit bee1bd5
Show file tree
Hide file tree
Showing 42 changed files with 1,156 additions and 703 deletions.
36 changes: 36 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,41 @@
# Changelog

## [v0.3.0](https://github.com/CovenantSQL/CovenantSQL/tree/v0.3.0) (2019-01-30)

[Full Changelog](https://github.com/CovenantSQL/CovenantSQL/compare/v0.2.0...v0.3.0)

**Closed issues:**

- Blocks are not written to chain [\#219](https://github.com/CovenantSQL/CovenantSQL/issues/219)

**Merged pull requests:**

- Improve database query performance [\#240](https://github.com/CovenantSQL/CovenantSQL/pull/240) ([xq262144](https://github.com/xq262144))
- Support query regulations and flag bit permissions [\#239](https://github.com/CovenantSQL/CovenantSQL/pull/239) ([xq262144](https://github.com/xq262144))
- Run each round sequentially to decrease running goroutines [\#238](https://github.com/CovenantSQL/CovenantSQL/pull/238) ([leventeliu](https://github.com/leventeliu))
- Fix bug: bad critical section for multiple values [\#237](https://github.com/CovenantSQL/CovenantSQL/pull/237) ([leventeliu](https://github.com/leventeliu))
- Add missing private key and rename apinode to fullnode [\#236](https://github.com/CovenantSQL/CovenantSQL/pull/236) ([ggicci](https://github.com/ggicci))
- Regen HashStablePack for v2.0.0 [\#235](https://github.com/CovenantSQL/CovenantSQL/pull/235) ([auxten](https://github.com/auxten))
- Use ~/.cql/ directory as default config location. [\#233](https://github.com/CovenantSQL/CovenantSQL/pull/233) ([laodouya](https://github.com/laodouya))
- GetCurrentBP also return BP follower [\#229](https://github.com/CovenantSQL/CovenantSQL/pull/229) ([auxten](https://github.com/auxten))
- Use 114 DNS for default [\#228](https://github.com/CovenantSQL/CovenantSQL/pull/228) ([auxten](https://github.com/auxten))
- Add metric web for cqld and cql-minerd [\#227](https://github.com/CovenantSQL/CovenantSQL/pull/227) ([auxten](https://github.com/auxten))
- Add testnet client init process test. Add a param 'fast' for GNTE test [\#226](https://github.com/CovenantSQL/CovenantSQL/pull/226) ([laodouya](https://github.com/laodouya))
- Fix bug to avoid ack DDoS and add timeout for connecting db [\#225](https://github.com/CovenantSQL/CovenantSQL/pull/225) ([zeqing-guo](https://github.com/zeqing-guo))
- Add readonly flag for fuse [\#224](https://github.com/CovenantSQL/CovenantSQL/pull/224) ([auxten](https://github.com/auxten))
- Add other cmd tools in observer image [\#222](https://github.com/CovenantSQL/CovenantSQL/pull/222) ([zeqing-guo](https://github.com/zeqing-guo))
- Add cql-utils option to wait for confirmation [\#221](https://github.com/CovenantSQL/CovenantSQL/pull/221) ([leventeliu](https://github.com/leventeliu))
- Add isolation level for xenomint state [\#220](https://github.com/CovenantSQL/CovenantSQL/pull/220) ([leventeliu](https://github.com/leventeliu))
- Add TransactionState MarshalHash [\#218](https://github.com/CovenantSQL/CovenantSQL/pull/218) ([auxten](https://github.com/auxten))
- Fix block producer genesis block hash mismatch [\#217](https://github.com/CovenantSQL/CovenantSQL/pull/217) ([leventeliu](https://github.com/leventeliu))
- Fix gitlab ci script pipline will not return failed when go test failed. [\#216](https://github.com/CovenantSQL/CovenantSQL/pull/216) ([laodouya](https://github.com/laodouya))
- Add query payload encode cache [\#215](https://github.com/CovenantSQL/CovenantSQL/pull/215) ([auxten](https://github.com/auxten))
- Client log optimize [\#214](https://github.com/CovenantSQL/CovenantSQL/pull/214) ([auxten](https://github.com/auxten))
- Add testnet compatibility test in CI process. [\#212](https://github.com/CovenantSQL/CovenantSQL/pull/212) ([laodouya](https://github.com/laodouya))
- Fix block producers forking on startup [\#211](https://github.com/CovenantSQL/CovenantSQL/pull/211) ([leventeliu](https://github.com/leventeliu))
- Coping with sqlchain soft forks [\#201](https://github.com/CovenantSQL/CovenantSQL/pull/201) ([xq262144](https://github.com/xq262144))
- Support JSON RPC API [\#164](https://github.com/CovenantSQL/CovenantSQL/pull/164) ([ggicci](https://github.com/ggicci))

## [v0.2.0](https://github.com/CovenantSQL/CovenantSQL/tree/v0.2.0) (2019-01-05)

[Full Changelog](https://github.com/CovenantSQL/CovenantSQL/compare/v0.1.0...v0.2.0)
Expand Down
74 changes: 9 additions & 65 deletions blockproducer/metastate.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,63 +375,6 @@ func (s *metaState) transferAccountToken(transfer *types.Transfer) (err error) {

}

func (s *metaState) transferAccountStableBalance(
sender, receiver proto.AccountAddress, amount uint64) (err error,
) {
if sender == receiver || amount == 0 {
return
}

// Create empty receiver account if not found
s.loadOrStoreAccountObject(receiver, &types.Account{Address: receiver})

var (
so, ro *types.Account
sd, rd, ok bool
)

// Load sender and receiver objects
if so, sd = s.dirty.accounts[sender]; !sd {
if so, ok = s.readonly.accounts[sender]; !ok {
err = ErrAccountNotFound
return
}
}
if ro, rd = s.dirty.accounts[receiver]; !rd {
if ro, ok = s.readonly.accounts[receiver]; !ok {
err = ErrAccountNotFound
return
}
}

// Try transfer
var (
sb = so.TokenBalance[types.Particle]
rb = ro.TokenBalance[types.Particle]
)
if err = safeSub(&sb, &amount); err != nil {
return
}
if err = safeAdd(&rb, &amount); err != nil {
return
}

// Proceed transfer
if !sd {
var cpy = deepcopy.Copy(so).(*types.Account)
so = cpy
s.dirty.accounts[sender] = cpy
}
if !rd {
var cpy = deepcopy.Copy(ro).(*types.Account)
ro = cpy
s.dirty.accounts[receiver] = cpy
}
so.TokenBalance[types.Particle] = sb
ro.TokenBalance[types.Particle] = rb
return
}

func (s *metaState) increaseAccountCovenantBalance(k proto.AccountAddress, amount uint64) error {
return s.increaseAccountToken(k, amount, types.Wave)
}
Expand All @@ -454,7 +397,7 @@ func (s *metaState) createSQLChain(addr proto.AccountAddress, id proto.DatabaseI
s.dirty.databases[id] = &types.SQLChainProfile{
ID: id,
Owner: addr,
Miners: make([]*types.MinerInfo, 0),
Miners: make(MinerInfos, 0),
Users: []*types.SQLChainUser{
{
Address: addr,
Expand Down Expand Up @@ -660,21 +603,21 @@ func (s *metaState) matchProvidersWithUser(tx *types.CreateDatabase) (err error)
log.Warnf("miner filtered %v", err)
}
// if got enough, break
if uint64(len(miners)) == minerCount {
if uint64(miners.Len()) == minerCount {
break
}
}
}

// not enough, find more miner(s)
if uint64(len(miners)) < minerCount {
if uint64(miners.Len()) < minerCount {
if uint64(len(tx.ResourceMeta.TargetMiners)) >= minerCount {
err = errors.Wrapf(err, "miners match target are not enough %d:%d", len(miners), minerCount)
err = errors.Wrapf(err, "miners match target are not enough %d:%d", miners.Len(), minerCount)
return
}
var newMiners MinerInfos
// create new merged map
newMiners, err = s.filterNMiners(tx, sender, int(minerCount)-len(miners))
newMiners, err = s.filterNMiners(tx, sender, int(minerCount)-miners.Len())
if err != nil {
return
}
Expand Down Expand Up @@ -784,7 +727,7 @@ func (s *metaState) filterNMiners(
for _, po := range allProviderMap {
newMiners, _ = filterAndAppendMiner(newMiners, po, tx, user)
}
if len(newMiners) < minerCount {
if newMiners.Len() < minerCount {
err = ErrNoEnoughMiner
return
}
Expand All @@ -794,11 +737,11 @@ func (s *metaState) filterNMiners(
}

func filterAndAppendMiner(
miners []*types.MinerInfo,
miners MinerInfos,
po *types.ProviderProfile,
req *types.CreateDatabase,
user proto.AccountAddress,
) (newMiners []*types.MinerInfo, err error) {
) (newMiners MinerInfos, err error) {
newMiners = miners
if !isProviderUserMatch(po.TargetUser, user) {
err = ErrMinerUserNotMatch
Expand Down Expand Up @@ -1075,6 +1018,7 @@ func (s *metaState) transferSQLChainTokenBalance(transfer *types.Transfer) (err
if transfer.Signee == nil {
err = ErrInvalidSender
log.WithError(err).Warning("invalid signee in applyTransaction")
return
}

realSender, err := crypto.PubKeyHash(transfer.Signee)
Expand Down
95 changes: 92 additions & 3 deletions blockproducer/metastate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ func TestMetaState(t *testing.T) {
So(err, ShouldBeNil)
err = ms.transferAccountToken(tran3)
So(err, ShouldEqual, ErrBalanceOverflow)

tran4 := &types.Transfer{
TransferHeader: types.TransferHeader{
Sender: addr2,
Expand All @@ -410,6 +411,34 @@ func TestMetaState(t *testing.T) {
err = ms.transferAccountToken(tran4)
So(err, ShouldBeNil)
ms.commit()

// wrong private sign test
tran5 := &types.Transfer{
TransferHeader: types.TransferHeader{
Sender: addr2,
Receiver: addr3,
Amount: 1,
TokenType: types.Particle,
Nonce: 1,
},
}
err = tran5.Sign(privKey3)
So(err, ShouldBeNil)
err = ms.transferAccountToken(tran5)
So(err, ShouldNotBeNil)

// nil sign test
tran6 := &types.Transfer{
TransferHeader: types.TransferHeader{
Sender: addr2,
Receiver: addr3,
Amount: 1,
TokenType: types.Particle,
Nonce: 1,
},
}
err = ms.transferAccountToken(tran6)
So(err, ShouldNotBeNil)
},
)
Convey(
Expand Down Expand Up @@ -881,15 +910,17 @@ func TestMetaState(t *testing.T) {
TokenType: 0,
NodeID: "0002111",
}
ms.dirty.provider[proto.AccountAddress(hash.HashH([]byte("10")))] = &types.ProviderProfile{
po, loaded = ms.loadOrStoreProviderObject(proto.AccountAddress(hash.HashH([]byte("10"))), &types.ProviderProfile{
TargetUser: []proto.AccountAddress{addr2},
GasPrice: 1,
LoadAvgPerCPU: 0.001,
Memory: 100,
Space: 100,
TokenType: 0,
NodeID: "0003111",
}
})
So(po, ShouldBeNil)
So(loaded, ShouldBeFalse)
ms.dirty.provider[proto.AccountAddress(hash.HashH([]byte("11")))] = &types.ProviderProfile{
TargetUser: []proto.AccountAddress{addr2},
GasPrice: 1,
Expand Down Expand Up @@ -1110,6 +1141,19 @@ func TestMetaState(t *testing.T) {
So(err, ShouldBeNil)
So(dbID, ShouldEqual, dbAccount.DatabaseID())
trans2.Nonce = nonce
//no sign err
err = ms.apply(trans2)
So(err, ShouldEqual, ErrInvalidSender)
//wrong key sign err
err = trans2.Sign(privKey2)
So(err, ShouldBeNil)
err = ms.apply(trans2)
So(err, ShouldNotBeNil)
//invalid sign
copy([]byte("invalid hash"), trans2.DataHash[:])
err = ms.apply(trans2)
So(err, ShouldNotBeNil)
//correct transfer
err = trans2.Sign(privKey3)
So(err, ShouldBeNil)
err = ms.apply(trans2)
Expand Down Expand Up @@ -1180,6 +1224,52 @@ func TestMetaState(t *testing.T) {
}
}

// transfer too much token
trans5 := types.NewTransfer(&types.TransferHeader{
Sender: addr3,
Receiver: dbAccount,
Amount: 18446744073709551615,
TokenType: types.Particle,
})
nonce, err = ms.nextNonce(addr3)
So(err, ShouldBeNil)
trans5.Nonce = nonce
err = trans5.Sign(privKey3)
So(err, ShouldBeNil)
err = ms.apply(trans5)
So(err, ShouldEqual, ErrInsufficientBalance)
profile, ok = ms.loadSQLChainObject(dbID)
So(ok, ShouldBeTrue)
for _, user := range profile.Users {
if user.Address == addr3 {
So(user.Status, ShouldEqual, types.Arrears)
break
}
}

// transfer wrong type of token
trans6 := types.NewTransfer(&types.TransferHeader{
Sender: addr3,
Receiver: dbAccount,
Amount: 4000000,
TokenType: -1,
})
nonce, err = ms.nextNonce(addr3)
So(err, ShouldBeNil)
trans6.Nonce = nonce
err = trans6.Sign(privKey3)
So(err, ShouldBeNil)
err = ms.apply(trans6)
So(err, ShouldEqual, ErrWrongTokenType)
profile, ok = ms.loadSQLChainObject(dbID)
So(ok, ShouldBeTrue)
for _, user := range profile.Users {
if user.Address == addr3 {
So(user.Status, ShouldEqual, types.Arrears)
break
}
}

// transfer enough token
trans4 := types.NewTransfer(&types.TransferHeader{
Sender: addr3,
Expand All @@ -1202,7 +1292,6 @@ func TestMetaState(t *testing.T) {
break
}
}

})
Convey("update key", func() {
invalidIk1 := &types.IssueKeys{}
Expand Down
Loading

0 comments on commit bee1bd5

Please sign in to comment.