Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
434387c
Add isolation level for xenomint state
leventeliu Jan 16, 2019
8a40fea
Minor fix
leventeliu Jan 16, 2019
526d41f
Fix minerd integration test
leventeliu Jan 17, 2019
3e0032c
Add test case for serializable level
leventeliu Jan 17, 2019
5393e18
Fix client test case
leventeliu Jan 17, 2019
495f14e
Merge branch 'beta' into feature/xeno_transaction
leventeliu Jan 17, 2019
ac68f6d
Reset miner log level
leventeliu Jan 17, 2019
3e492e9
Add cql-utils option to wait for confirmation
leventeliu Jan 18, 2019
441a1ef
Add default case in tx state switch block
leventeliu Jan 18, 2019
e1c5350
Minor fix
leventeliu Jan 18, 2019
bdf8adf
Add other cmd tool in observer image
zeqing-guo Jan 18, 2019
cfde40f
Prune useless binary tools
zeqing-guo Jan 20, 2019
b9e6d72
Merge pull request #222 from CovenantSQL/feature/observer_docker
leventeliu Jan 21, 2019
95423a3
Add method to wait for transaction confirmation
leventeliu Jan 21, 2019
525b2ab
Merge branch 'develop' into feature/transfer
leventeliu Jan 21, 2019
00acb22
Minor fix
leventeliu Jan 21, 2019
da90c14
Merge pull request #221 from CovenantSQL/feature/transfer
leventeliu Jan 21, 2019
ba78400
Keep HashStablePack latest before generate code
Dec 27, 2018
ef1c4f2
Add readonly flag for fuse
Dec 27, 2018
667d507
Make fuse blocksize = 128KB
Jan 17, 2019
af35d0e
Remove out of date comment
auxten Jan 21, 2019
e46909f
Merge pull request #224 from CovenantSQL/feature/fuse
auxten Jan 21, 2019
4aedb89
Add parameter for eventual consistency
leventeliu Jan 21, 2019
941c79a
Merge remote-tracking branch 'origin/develop' into feature/xeno_trans…
leventeliu Jan 22, 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
17 changes: 17 additions & 0 deletions blockproducer/interfaces/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,23 @@ const (
TransactionStateNotFound
)

func (s TransactionState) String() string {
switch s {
case TransactionStatePending:
return "Pending"
case TransactionStatePacked:
return "Packed"
case TransactionStateConfirmed:
return "Confirmed"
case TransactionStateExpired:
return "Expired"
case TransactionStateNotFound:
return "Not Found"
default:
return "Unknown"
}
}

// Transaction is the interface implemented by an object that can be verified and processed by
// block producers.
type Transaction interface {
Expand Down
20 changes: 11 additions & 9 deletions blockproducer/metastate.go
Original file line number Diff line number Diff line change
Expand Up @@ -729,15 +729,17 @@ func (s *metaState) matchProvidersWithUser(tx *types.CreateDatabase) (err error)

// create sqlchain
sp := &types.SQLChainProfile{
ID: dbID,
Address: dbAddr,
Period: sqlchainPeriod,
GasPrice: tx.GasPrice,
TokenType: types.Particle,
Owner: sender,
Users: users,
EncodedGenesis: enc.Bytes(),
Miners: miners,
ID: dbID,
Address: dbAddr,
Period: sqlchainPeriod,
GasPrice: tx.GasPrice,
LastUpdatedHeight: 0,
TokenType: types.Particle,
Owner: sender,
Miners: miners,
Users: users,
EncodedGenesis: enc.Bytes(),
Meta: tx.ResourceMeta,
}

if _, loaded := s.loadSQLChainObject(dbID); loaded {
Expand Down
55 changes: 53 additions & 2 deletions client/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/CovenantSQL/CovenantSQL/conf"
"github.com/CovenantSQL/CovenantSQL/crypto"
"github.com/CovenantSQL/CovenantSQL/crypto/asymmetric"
"github.com/CovenantSQL/CovenantSQL/crypto/hash"
"github.com/CovenantSQL/CovenantSQL/crypto/kms"
"github.com/CovenantSQL/CovenantSQL/proto"
"github.com/CovenantSQL/CovenantSQL/route"
Expand Down Expand Up @@ -260,7 +261,7 @@ func GetTokenBalance(tt types.TokenType) (balance uint64, err error) {

// UpdatePermission sends UpdatePermission transaction to chain.
func UpdatePermission(targetUser proto.AccountAddress,
targetChain proto.AccountAddress, perm types.UserPermission) (err error) {
targetChain proto.AccountAddress, perm types.UserPermission) (txHash hash.Hash, err error) {
if atomic.LoadUint32(&driverInitialized) == 0 {
err = ErrNotInitialized
return
Expand Down Expand Up @@ -307,11 +308,14 @@ func UpdatePermission(targetUser proto.AccountAddress,
return
}

txHash = up.Hash()
return
}

// TransferToken send Transfer transaction to chain.
func TransferToken(targetUser proto.AccountAddress, amount uint64, tokenType types.TokenType) (err error) {
func TransferToken(targetUser proto.AccountAddress, amount uint64, tokenType types.TokenType) (
txHash hash.Hash, err error,
) {
if atomic.LoadUint32(&driverInitialized) == 0 {
err = ErrNotInitialized
return
Expand Down Expand Up @@ -359,6 +363,53 @@ func TransferToken(targetUser proto.AccountAddress, amount uint64, tokenType typ
return
}

txHash = tran.Hash()
return
}

// WaitTxConfirmation waits for the transaction with target hash txHash to be confirmed. It also
// returns if any error occurs or a final state is returned from BP.
func WaitTxConfirmation(
ctx context.Context, txHash hash.Hash) (state interfaces.TransactionState, err error,
) {
var (
ticker = time.NewTicker(1 * time.Second)
method = route.MCCQueryTxState
req = &types.QueryTxStateReq{Hash: txHash}
resp = &types.QueryTxStateResp{}
)
defer ticker.Stop()
for {
if err = requestBP(method, req, resp); err != nil {
err = errors.Wrapf(err, "failed to call %s", method)
return
}

state = resp.State
log.WithFields(log.Fields{
"tx_hash": txHash,
"tx_state": state,
}).Debug("waiting for tx confirmation")

switch state {
case interfaces.TransactionStatePending:
case interfaces.TransactionStatePacked:
case interfaces.TransactionStateConfirmed,
interfaces.TransactionStateExpired,
interfaces.TransactionStateNotFound:
return
default:
err = errors.Errorf("unknown transaction state %d", state)
return
}

select {
case <-ticker.C:
case <-ctx.Done():
err = ctx.Err()
return
}
}
return
}

Expand Down
8 changes: 6 additions & 2 deletions client/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package client

import (
"bytes"
"database/sql"
"fmt"
"io/ioutil"
"math/rand"
Expand Down Expand Up @@ -149,8 +150,11 @@ func startTestService() (stopTestService func(), tempDir string, err error) {
req = new(types.UpdateService)
req.Header.Op = types.CreateDB
req.Header.Instance = types.ServiceInstance{
DatabaseID: dbID,
Peers: peers,
DatabaseID: dbID,
Peers: peers,
ResourceMeta: types.ResourceMeta{
IsolationLevel: int(sql.LevelReadUncommitted),
},
GenesisBlock: block,
}
if req.Header.Signee, err = kms.GetLocalPublicKey(); err != nil {
Expand Down
8 changes: 5 additions & 3 deletions client/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"context"
"database/sql"
"database/sql/driver"

"github.com/pkg/errors"
)

// ExecuteTx starts a transaction, and runs fn in it
Expand All @@ -39,11 +41,11 @@ func ExecuteTx(
func ExecuteInTx(tx driver.Tx, fn func() error) (err error) {
err = fn()
if err == nil {
// Ignore commit errors. The tx has already been committed by RELEASE.
err = tx.Commit()
if err != nil {
err = errors.Wrapf(err, "exec in tx")
}
} else {
// We always need to execute a Rollback() so sql.DB releases the
// connection.
_ = tx.Rollback()
}
return
Expand Down
2 changes: 1 addition & 1 deletion cmd/cql-fuse/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import (

// BlockSize is the size of each data block. It must not
// change throughout the lifetime of the filesystem.
const BlockSize = 4 << 10 // 4KB
const BlockSize = 128 << 10 // 128KB

func min(a, b uint64) uint64 {
if a < b {
Expand Down
3 changes: 3 additions & 0 deletions cmd/cql-fuse/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,9 @@ func TestShrinkGrow(t *testing.T) {
if data, err = tryGrow(db, data, id, BlockSize*5); err != nil {
log.Fatal(err)
}
if data, err = tryGrow(db, data, id, BlockSize*999); err != nil {
log.Fatal(err)
}

// Shrink it down to 0.
if data, err = tryShrink(db, data, id, 0); err != nil {
Expand Down
30 changes: 21 additions & 9 deletions cmd/cql-fuse/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,24 @@ import (
)

var usage = func() {
fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0])
fmt.Fprintf(os.Stderr, " %s -config <config> -dsn <dsn> -mount <mountpoint>\n\n", os.Args[0])
_, _ = fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0])
_, _ = fmt.Fprintf(os.Stderr, " %s -config <config> -dsn <dsn> -mount <mountpoint>\n\n", os.Args[0])
flag.PrintDefaults()
}

func main() {
var config, dsn, mountPoint, password string

var (
config string
dsn string
mountPoint string
password string
readOnly bool
)
flag.StringVar(&config, "config", "./conf/config.yaml", "config file path")
flag.StringVar(&mountPoint, "mount", "./", "dir to mount")
flag.StringVar(&dsn, "dsn", "", "database url")
flag.StringVar(&password, "password", "", "master key password for covenantsql")
flag.BoolVar(&readOnly, "readonly", false, "mount read only volume")
flag.Usage = usage
flag.Parse()

Expand All @@ -102,11 +108,12 @@ func main() {
log.Fatal(err)
}

cfg, err := client.ParseDSN(dsn)
if err != nil {
log.Fatal(err)
}

db, err := sql.Open("covenantsql", dsn)
db, err := sql.Open("covenantsql", cfg.FormatDSN())
if err != nil {
log.Fatal(err)
}
Expand All @@ -118,13 +125,18 @@ func main() {
}

cfs := CFS{db}
opts := make([]fuse.MountOption, 0, 5)
opts = append(opts, fuse.FSName("CovenantFS"))
opts = append(opts, fuse.Subtype("CovenantFS"))
opts = append(opts, fuse.LocalVolume())
opts = append(opts, fuse.VolumeName(cfg.DatabaseID))
if readOnly {
opts = append(opts, fuse.ReadOnly())
}
// Mount filesystem.
c, err := fuse.Mount(
mountPoint,
fuse.FSName("CovenantFS"),
fuse.Subtype("CovenantFS"),
fuse.LocalVolume(),
fuse.VolumeName(""),
opts...,
)
if err != nil {
log.Fatal(err)
Expand Down
8 changes: 7 additions & 1 deletion cmd/cql-minerd/bench.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,10 @@ go test -bench=^BenchmarkMinerOneNoSign$ -benchtime=10s -run ^$ && \
go test -bench=^BenchmarkMinerTwo$ -benchtime=10s -run ^$ && \
go test -bench=^BenchmarkMinerTwoNoSign$ -benchtime=10s -run ^$ && \
go test -bench=^BenchmarkMinerThree$ -benchtime=10s -run ^$ && \
go test -bench=^BenchmarkMinerThreeNoSign$ -benchtime=10s -run ^$
go test -bench=^BenchmarkMinerThreeNoSign$ -benchtime=10s -run ^$ && \
go test -bench=^BenchmarkMinerOneWithEventualConsistency$ -benchtime=10s -run ^$ && \
go test -bench=^BenchmarkMinerOneNoSignWithEventualConsistency$ -benchtime=10s -run ^$ && \
go test -bench=^BenchmarkMinerTwoWithEventualConsistency$ -benchtime=10s -run ^$ && \
go test -bench=^BenchmarkMinerTwoNoSignWithEventualConsistency$ -benchtime=10s -run ^$ && \
go test -bench=^BenchmarkMinerThreeWithEventualConsistency$ -benchtime=10s -run ^$ && \
go test -bench=^BenchmarkMinerThreeNoSignWithEventualConsistency$ -benchtime=10s -run ^$
Loading