diff --git a/blockproducer/interfaces/transaction.go b/blockproducer/interfaces/transaction.go index e074e6ea3..5de3be02b 100644 --- a/blockproducer/interfaces/transaction.go +++ b/blockproducer/interfaces/transaction.go @@ -72,6 +72,8 @@ const ( TransactionTypeIssueKeys // TransactionTypeUpdateBilling defines SQLChain update billing information. TransactionTypeUpdateBilling + // TransactionTypeSetPublicMiner defines miners should/should not provide public service. + TransactionTypeSetPublicMiner // TransactionTypeNumber defines transaction types number. TransactionTypeNumber ) @@ -102,6 +104,8 @@ func (t TransactionType) String() string { return "IssueKeys" case TransactionTypeUpdateBilling: return "UpdateBilling" + case TransactionTypeSetPublicMiner: + return "SetPublicMiner" default: return "Unknown" } diff --git a/blockproducer/metastate.go b/blockproducer/metastate.go index 5f69abe09..993bf7599 100644 --- a/blockproducer/metastate.go +++ b/blockproducer/metastate.go @@ -18,6 +18,7 @@ package blockproducer import ( "bytes" + "encoding/binary" "sort" "github.com/mohae/deepcopy" @@ -26,6 +27,7 @@ import ( pi "github.com/CovenantSQL/CovenantSQL/blockproducer/interfaces" "github.com/CovenantSQL/CovenantSQL/conf" "github.com/CovenantSQL/CovenantSQL/crypto" + "github.com/CovenantSQL/CovenantSQL/crypto/hash" "github.com/CovenantSQL/CovenantSQL/proto" "github.com/CovenantSQL/CovenantSQL/types" "github.com/CovenantSQL/CovenantSQL/utils" @@ -516,6 +518,8 @@ func (s *metaState) updateProviderList(tx *types.ProvideService, height uint32) return } + var allowPublicService bool + if height >= conf.BPHeightCIPFixProvideService { // load previous provider object po, loaded := s.loadProviderObject(sender) @@ -525,6 +529,7 @@ func (s *metaState) updateProviderList(tx *types.ProvideService, height uint32) return } + allowPublicService = po.AllowPublicService s.deleteProviderObject(sender) } } @@ -546,11 +551,16 @@ func (s *metaState) updateProviderList(tx *types.ProvideService, height uint32) GasPrice: tx.GasPrice, NodeID: tx.NodeID, } + + if height >= conf.BPHeightCIPSetPublicMiner { + pp.AllowPublicService = allowPublicService + } + s.dirty.provider[sender] = &pp return } -func (s *metaState) matchProvidersWithUser(tx *types.CreateDatabase) (err error) { +func (s *metaState) matchProvidersWithUser(tx *types.CreateDatabase, height uint32) (err error) { log.Infof("create database: %s", tx.Hash()) sender, err := crypto.PubKeyHash(tx.Signee) if err != nil { @@ -571,7 +581,11 @@ func (s *metaState) matchProvidersWithUser(tx *types.CreateDatabase) (err error) err = ErrInvalidMinerCount return } + minerCount := uint64(tx.ResourceMeta.Node) + if tx.ResourceMeta.Version >= conf.ResourceMetaSupportingStandbyNodeVersion { + minerCount += uint64(tx.ResourceMeta.StandbyNode) + } minAdvancePayment := minDeposit(tx.GasPrice, minerCount) @@ -585,12 +599,12 @@ func (s *metaState) matchProvidersWithUser(tx *types.CreateDatabase) (err error) miners := make(MinerInfos, 0, minerCount) for _, m := range tx.ResourceMeta.TargetMiners { - if po, loaded := s.loadProviderObject(m); !loaded { + if po, loaded := s.loadProviderObject(m); !loaded || po.IsConsumed { + err = ErrNoSuchMiner log.WithFields(log.Fields{ "miner_addr": m, "user_addr": sender, }).Error(err) - err = ErrNoSuchMiner continue } else { miners, err = filterAndAppendMiner(miners, po, tx, sender) @@ -612,7 +626,7 @@ func (s *metaState) matchProvidersWithUser(tx *types.CreateDatabase) (err error) } var newMiners MinerInfos // create new merged map - newMiners, err = s.filterNMiners(tx, sender, int(minerCount)-miners.Len()) + newMiners, err = s.filterNMiners(tx, sender, int(minerCount)-miners.Len(), height) if err != nil { return } @@ -664,6 +678,18 @@ func (s *metaState) matchProvidersWithUser(tx *types.CreateDatabase) (err error) return } + var ( + normalMiners MinerInfos + standbyMiners MinerInfos + ) + + if tx.ResourceMeta.Version >= conf.ResourceMetaSupportingStandbyNodeVersion { + normalMiners = miners[:int(tx.ResourceMeta.Node)] + standbyMiners = miners[int(tx.ResourceMeta.Node):] + } else { + normalMiners = miners + } + // create sqlchain sp := &types.SQLChainProfile{ ID: dbID, @@ -673,7 +699,8 @@ func (s *metaState) matchProvidersWithUser(tx *types.CreateDatabase) (err error) LastUpdatedHeight: 0, TokenType: types.Particle, Owner: sender, - Miners: miners, + Miners: normalMiners, + StandbyMiners: standbyMiners, Users: users, EncodedGenesis: enc.Bytes(), Meta: tx.ResourceMeta, @@ -686,6 +713,17 @@ func (s *metaState) matchProvidersWithUser(tx *types.CreateDatabase) (err error) s.dirty.accounts[dbAddr] = &types.Account{Address: dbAddr} s.dirty.databases[dbID] = sp for _, miner := range miners { + if height >= conf.BPHeightCIPSetPublicMiner { + if po, loaded := s.loadProviderObject(miner.Address); loaded && po.AllowPublicService { + s.dirty.provider[miner.Address] = &types.ProviderProfile{ + Provider: miner.Address, + IsConsumed: true, + AllowPublicService: true, + // leave all values including deposit as blank + } + continue + } + } s.deleteProviderObject(miner.Address) } log.Infof("success create sqlchain with database ID: %s", dbID) @@ -695,7 +733,8 @@ func (s *metaState) matchProvidersWithUser(tx *types.CreateDatabase) (err error) func (s *metaState) filterNMiners( tx *types.CreateDatabase, user proto.AccountAddress, - minerCount int) ( + minerCount int, + height uint32) ( m MinerInfos, err error, ) { // create new merged map @@ -720,6 +759,13 @@ func (s *metaState) filterNMiners( newMiners := make(MinerInfos, 0, len(allProviderMap)/4) // filter all miners to slice and sort for _, po := range allProviderMap { + if height >= conf.BPHeightCIPSetPublicMiner { + if po.IsConsumed || (!po.AllowPublicService && len(po.TargetUser) == 0) { + // not yet consumed + // not supporting public service, and want to provide public service + continue + } + } newMiners, _ = filterAndAppendMiner(newMiners, po, tx, user) } if newMiners.Len() < minerCount { @@ -727,10 +773,33 @@ func (s *metaState) filterNMiners( return } - sort.Slice(newMiners, newMiners.Less) + if tx.ResourceMeta.Version >= conf.ResourceMetaSupportingStandbyNodeVersion { + // get miner with nonce offset, use first byte of account address and nonce value + accountAddr := tx.GetAccountAddress() + accountNonce := tx.GetAccountNonce() + + sort.Slice(newMiners, func(i, j int) bool { + return bytes.Compare( + minerSortFactor(newMiners[i].NodeID, accountAddr, accountNonce), + minerSortFactor(newMiners[j].NodeID, accountAddr, accountNonce)) < 0 + }) + } else { + sort.Slice(newMiners, newMiners.Less) + } + return newMiners[:minerCount], nil } +func minerSortFactor(nodeID proto.NodeID, sender proto.AccountAddress, nonce pi.AccountNonce) []byte { + var buf bytes.Buffer + if rawNode := nodeID.ToRawNodeID(); rawNode != nil { + buf.Write(rawNode.Hash[:]) + } + buf.Write(sender[:]) + _ = binary.Write(&buf, binary.BigEndian, uint32(nonce)) + return hash.HashB(buf.Bytes()) +} + func filterAndAppendMiner( miners MinerInfos, po *types.ProviderProfile, @@ -998,6 +1067,57 @@ func (s *metaState) updateBilling(tx *types.UpdateBilling) (err error) { return } +func (s *metaState) setPublicMiner(tx *types.SetPublicMiner, height uint32) (err error) { + log.WithFields(log.Fields{ + "tx_hash": tx.Hash(), + "sender": tx.GetAccountAddress(), + "miner": tx.Miner, + "enabled": tx.Enabled, + }).Debug("set public miner") + + // check if the signer is block producer + if tx.Signee == nil || !tx.Signee.IsEqual(conf.GConf.BP.PublicKey) { + err = ErrInvalidSender + log.WithError(err).Warning("invalid signee for setting public miners") + return + } + + if height < conf.BPHeightCIPSetPublicMiner { + err = ErrUnknownTransactionType + log.WithError(err).Warning("set public miner tx sent before enabled state") + return + } + + po, loaded := s.loadProviderObject(tx.Miner) + if loaded { + if tx.Enabled > 0 { + pp := deepcopy.Copy(po).(*types.ProviderProfile) + pp.AllowPublicService = true + s.dirty.provider[tx.Miner] = pp + } else { + if po.IsConsumed { + s.deleteProviderObject(tx.Miner) + } else { + pp := deepcopy.Copy(po).(*types.ProviderProfile) + pp.AllowPublicService = false + s.dirty.provider[tx.Miner] = pp + } + } + } else { + if tx.Enabled > 0 { + s.dirty.provider[tx.Miner] = &types.ProviderProfile{ + Provider: tx.Miner, + IsConsumed: true, + AllowPublicService: true, + // leave all values including deposit as blank + } + } else { + // nothing to do, no provider service means no privilege to public service + } + } + return +} + func (s *metaState) loadROSQLChains(addr proto.AccountAddress) (dbs []*types.SQLChainProfile) { for _, db := range s.readonly.databases { for _, miner := range db.Miners { @@ -1139,13 +1259,15 @@ func (s *metaState) applyTransaction(tx pi.Transaction, height uint32) (err erro case *types.ProvideService: err = s.updateProviderList(t, height) case *types.CreateDatabase: - err = s.matchProvidersWithUser(t) + err = s.matchProvidersWithUser(t, height) case *types.UpdatePermission: err = s.updatePermission(t) case *types.IssueKeys: err = s.updateKeys(t) case *types.UpdateBilling: err = s.updateBilling(t) + case *types.SetPublicMiner: + err = s.setPublicMiner(t, height) case *pi.TransactionWrapper: // call again using unwrapped transaction err = s.applyTransaction(t.Unwrap(), height) diff --git a/client/driver.go b/client/driver.go index 8756f5694..11cd7ce8a 100644 --- a/client/driver.go +++ b/client/driver.go @@ -111,6 +111,7 @@ type ResourceMeta struct { UseEventualConsistency bool `json:"eventual-consistency,omitempty"` // use eventual consistency replication if enabled ConsistencyLevel float64 `json:"consistency-level,omitempty"` // customized strong consistency level IsolationLevel int `json:"isolation-level,omitempty"` // customized isolation level + StandbyNode uint16 `json:"standby-node,omitempty"` // standby node count for recovery GasPrice uint64 `json:"gas-price"` // customized gas price AdvancePayment uint64 `json:"advance-payment"` // customized advance payment @@ -196,20 +197,31 @@ func Create(meta ResourceMeta) (txHash hash.Hash, dsn string, err error) { meta.AdvancePayment = DefaultAdvancePayment } + rsMeta := types.ResourceMeta{ + TargetMiners: meta.TargetMiners, + Node: meta.Node, + Space: meta.Space, + Memory: meta.Memory, + LoadAvgPerCPU: meta.LoadAvgPerCPU, + EncryptionKey: meta.EncryptionKey, + UseEventualConsistency: meta.UseEventualConsistency, + ConsistencyLevel: meta.ConsistencyLevel, + IsolationLevel: meta.IsolationLevel, + StandbyNode: meta.StandbyNode, + + // version hint + Version: int32((*types.ResourceMeta)(nil).HSPDefaultVersion()), + } + + if meta.StandbyNode == 0 { + // use old version for compatibility + rsMeta.Version = 0 + } + req.TTL = 1 req.Tx = types.NewCreateDatabase(&types.CreateDatabaseHeader{ - Owner: clientAddr, - ResourceMeta: types.ResourceMeta{ - TargetMiners: meta.TargetMiners, - Node: meta.Node, - Space: meta.Space, - Memory: meta.Memory, - LoadAvgPerCPU: meta.LoadAvgPerCPU, - EncryptionKey: meta.EncryptionKey, - UseEventualConsistency: meta.UseEventualConsistency, - ConsistencyLevel: meta.ConsistencyLevel, - IsolationLevel: meta.IsolationLevel, - }, + Owner: clientAddr, + ResourceMeta: rsMeta, GasPrice: meta.GasPrice, AdvancePayment: meta.AdvancePayment, TokenType: types.Particle, diff --git a/cmd/cql-minerd/integration_test.go b/cmd/cql-minerd/integration_test.go index ceb079a8c..7c56cf838 100644 --- a/cmd/cql-minerd/integration_test.go +++ b/cmd/cql-minerd/integration_test.go @@ -23,6 +23,7 @@ import ( "database/sql" "flag" "fmt" + "github.com/CovenantSQL/CovenantSQL/crypto/hash" "io/ioutil" "math/rand" "os" @@ -36,7 +37,7 @@ import ( "testing" "time" - sqlite3 "github.com/CovenantSQL/go-sqlite3-encrypt" + "github.com/CovenantSQL/go-sqlite3-encrypt" . "github.com/smartystreets/goconvey/convey" "github.com/CovenantSQL/CovenantSQL/client" @@ -120,6 +121,7 @@ func startNodes() { []string{"-config", FJ(testWorkingDir, "./integration/node_0/config.yaml"), "-test.coverprofile", FJ(baseDir, "./cmd/cql-minerd/leader.cover.out"), "-metric-web", "0.0.0.0:13122", + "-log-level", "debug", }, "leader", testWorkingDir, logDir, true, ); err == nil { @@ -132,6 +134,7 @@ func startNodes() { []string{"-config", FJ(testWorkingDir, "./integration/node_1/config.yaml"), "-test.coverprofile", FJ(baseDir, "./cmd/cql-minerd/follower1.cover.out"), "-metric-web", "0.0.0.0:13121", + "-log-level", "debug", }, "follower1", testWorkingDir, logDir, false, ); err == nil { @@ -144,6 +147,7 @@ func startNodes() { []string{"-config", FJ(testWorkingDir, "./integration/node_2/config.yaml"), "-test.coverprofile", FJ(baseDir, "./cmd/cql-minerd/follower2.cover.out"), "-metric-web", "0.0.0.0:13120", + "-log-level", "debug", }, "follower2", testWorkingDir, logDir, false, ); err == nil { @@ -381,6 +385,7 @@ func TestFullProcess(t *testing.T) { So(err, ShouldBeNil) var ( + bpPrivKey *asymmetric.PrivateKey clientPrivKey *asymmetric.PrivateKey clientAddr proto.AccountAddress @@ -389,6 +394,8 @@ func TestFullProcess(t *testing.T) { ) // get miners' private keys + bpPrivKey, err = kms.LoadPrivateKey(FJ(testWorkingDir, "./integration/node_0/private.key"), []byte{}) + So(err, ShouldBeNil) minersPrivKeys[0], err = kms.LoadPrivateKey(FJ(testWorkingDir, "./integration/node_miner_0/private.key"), []byte{}) So(err, ShouldBeNil) minersPrivKeys[1], err = kms.LoadPrivateKey(FJ(testWorkingDir, "./integration/node_miner_1/private.key"), []byte{}) @@ -408,6 +415,10 @@ func TestFullProcess(t *testing.T) { clientAddr, err = crypto.PubKeyHash(clientPrivKey.PubKey()) So(err, ShouldBeNil) + // set public miner for public service + err = sendSetPublicMiner(bpPrivKey, minersAddrs) + So(err, ShouldBeNil) + // client send create database transaction meta := client.ResourceMeta{ TargetMiners: minersAddrs, @@ -998,6 +1009,61 @@ func benchOutsideMinerWithTargetMinerList( benchDB(b, db, minerCount > 0) } +func sendSetPublicMiner(bpKey *asymmetric.PrivateKey, publicMiners []proto.AccountAddress) (err error) { + var bpAddr proto.AccountAddress + bpAddr, err = crypto.PubKeyHash(bpKey.PubKey()) + if err != nil { + return + } + + var ( + nonceReq = &types.NextAccountNonceReq{Addr: bpAddr} + nonceResp = &types.NextAccountNonceResp{} + ) + + err = rpc.RequestBP(route.MCCNextAccountNonce.String(), nonceReq, nonceResp) + if err != nil { + return + } + + var ( + nonce = nonceResp.Nonce + lastHash hash.Hash + ) + + for _, miner := range publicMiners { + var ( + tx = types.NewSetPublicMiner(&types.SetPublicMinerHeader{ + Miner: miner, + Enabled: 1, + Nonce: nonce, + }) + req = &types.AddTxReq{TTL: 1} + resp = &types.AddTxResp{} + ) + + if err = tx.Sign(bpKey); err != nil { + return + } + + req.Tx = tx + + err = rpc.RequestBP(route.MCCAddTx.String(), req, resp) + if err != nil { + return + } + + lastHash = tx.Hash() + nonce++ + } + + ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute) + defer cancel() + _, err = client.WaitTxConfirmation(ctx, lastHash) + + return +} + func BenchmarkClientOnly(b *testing.B) { Convey("bench three node", b, func() { benchMiner(b, 0) diff --git a/conf/parameters.go b/conf/parameters.go index c6f9251f0..daf6eaa9d 100644 --- a/conf/parameters.go +++ b/conf/parameters.go @@ -28,5 +28,11 @@ const ( // Block producer chain improvements proposal heights. const ( - BPHeightCIPFixProvideService = 675550 // inclusive, in 2019-5-15 16:11:40 +08:00 + BPHeightCIPFixProvideService = 675550 // inclusive, in 2019-05-15 16:11:40 +08:00 + BPHeightCIPSetPublicMiner = 1147300 // inclusive, in 2019-07-09 06:36:40 +08:00 +) + +// ResourceMeta version number for supporting standby nodes. +const ( + ResourceMetaSupportingStandbyNodeVersion = 1 ) diff --git a/test/compatibility/node_0/config.yaml b/test/compatibility/node_0/config.yaml index 61f590880..1ab3b5572 100644 --- a/test/compatibility/node_0/config.yaml +++ b/test/compatibility/node_0/config.yaml @@ -56,6 +56,9 @@ BlockProducer: - Address: 9e1618775cceeb19f110e04fbc6c5bca6c8e4e9b116e193a42fe69bf602e7bcd StableCoinBalance: 10000000000000000000 CovenantCoinBalance: 10000000000000000000 + - Address: 8d7604acfdb391891a4c795f0939425b6d58bd50a81e579d15f06ecd381ad549 + StableCoinBalance: 10000000000000000000 + CovenantCoinBalance: 10000000000000000000 KnownNodes: - ID: 00000bef611d346c0cbe1beaa76e7f0ed705a194fdf9ac3a248ec70e9c198bf9 Nonce: diff --git a/test/compatibility/node_1/config.yaml b/test/compatibility/node_1/config.yaml index 4571d0040..26298cd69 100644 --- a/test/compatibility/node_1/config.yaml +++ b/test/compatibility/node_1/config.yaml @@ -56,6 +56,9 @@ BlockProducer: - Address: 9e1618775cceeb19f110e04fbc6c5bca6c8e4e9b116e193a42fe69bf602e7bcd StableCoinBalance: 10000000000000000000 CovenantCoinBalance: 10000000000000000000 + - Address: 8d7604acfdb391891a4c795f0939425b6d58bd50a81e579d15f06ecd381ad549 + StableCoinBalance: 10000000000000000000 + CovenantCoinBalance: 10000000000000000000 KnownNodes: - ID: 00000bef611d346c0cbe1beaa76e7f0ed705a194fdf9ac3a248ec70e9c198bf9 Nonce: diff --git a/test/compatibility/node_2/config.yaml b/test/compatibility/node_2/config.yaml index e651e3aa0..a20ca024e 100644 --- a/test/compatibility/node_2/config.yaml +++ b/test/compatibility/node_2/config.yaml @@ -56,6 +56,9 @@ BlockProducer: - Address: 9e1618775cceeb19f110e04fbc6c5bca6c8e4e9b116e193a42fe69bf602e7bcd StableCoinBalance: 10000000000000000000 CovenantCoinBalance: 10000000000000000000 + - Address: 8d7604acfdb391891a4c795f0939425b6d58bd50a81e579d15f06ecd381ad549 + StableCoinBalance: 10000000000000000000 + CovenantCoinBalance: 10000000000000000000 KnownNodes: - ID: 00000bef611d346c0cbe1beaa76e7f0ed705a194fdf9ac3a248ec70e9c198bf9 Nonce: diff --git a/test/compatibility/node_bp_c/config.yaml b/test/compatibility/node_bp_c/config.yaml new file mode 100644 index 000000000..60b0df76c --- /dev/null +++ b/test/compatibility/node_bp_c/config.yaml @@ -0,0 +1,100 @@ +UseTestMasterKey: true +WorkingRoot: "" +PubKeyStoreFile: "" +PrivateKeyFile: private.key +WalletAddress: 8d7604acfdb391891a4c795f0939425b6d58bd50a81e579d15f06ecd381ad549 +DHTFileName: "" +ListenAddr: "" +ListenDirectAddr: "" +ThisNodeID: 0000000e930b108b13739215d0139275354e242b500392e48ddb5ae71eb2b1b9 +QPS: 0 +BillingBlockCount: 0 +ChainBusPeriod: 0s +BPPeriod: 0s +BPTick: 0s +SQLChainPeriod: 0s +SQLChainTick: 0s +SQLChainTTL: 0 +MinProviderDeposit: 0 +ValidDNSKeys: + koPbw9wmYZ7ggcjnQ6ayHyhHaDNMYELKTqT+qRGrZpWSccr/lBcrm10Z1PuQHB3Azhii+sb0PYFkH1ruxLhe5g==: cloudflare.com + mdsswUyr3DPW132mOi8V9xESWE8jTo0dxCjjnopKl+GqJxpVXckHAeF+KkxLbxILfDLUT0rAK9iUzy1L53eKGQ==: cloudflare.com + oJMRESz5E4gYzS/q6XDrvU1qMPYIjCWzJaOau8XNEZeqCYKD5ar0IRd8KqXXFJkqmVfRvMGPmM1x8fGAa2XhSA==: cloudflare.com +MinNodeIDDifficulty: 2 +DNSSeed: + EnforcedDNSSEC: false + DNSServers: + - 1.1.1.1 + - 202.46.34.74 + - 202.46.34.75 + - 202.46.34.76 +BlockProducer: + PublicKey: "02c76216704d797c64c58bc11519fb68582e8e63de7e5b3b2dbbbe8733efe5fd24" + NodeID: 00000bef611d346c0cbe1beaa76e7f0ed705a194fdf9ac3a248ec70e9c198bf9 + Nonce: + a: 313283 + b: 0 + c: 0 + d: 0 + ChainFileName: "chain.db" + BPGenesisInfo: + Version: 1 + BlockHash: f745ca6427237aac858dd3c7f2df8e6f3c18d0f1c164e07a1c6b8eebeba6b154 + Producer: 0000000000000000000000000000000000000000000000000000000000000001 + MerkleRoot: 0000000000000000000000000000000000000000000000000000000000000001 + ParentHash: 0000000000000000000000000000000000000000000000000000000000000001 + Timestamp: 2018-08-13T21:59:59.12Z + BaseAccounts: + - Address: ba0ba731c7a76ccef2c1170f42038f7e228dfb474ef0190dfe35d9a37911ed37 + StableCoinBalance: 10000000000000000000 + CovenantCoinBalance: 10000000000000000000 + - Address: 1a7b0959bbd0d0ec529278a61c0056c277bffe75b2646e1699b46b10a90210be + StableCoinBalance: 10000000000000000000 + CovenantCoinBalance: 10000000000000000000 + - Address: 9235bc4130a2ed4e6c35ea189dab35198ebb105640bedb97dd5269cc80863b16 + StableCoinBalance: 10000000000000000000 + CovenantCoinBalance: 10000000000000000000 + - Address: 9e1618775cceeb19f110e04fbc6c5bca6c8e4e9b116e193a42fe69bf602e7bcd + StableCoinBalance: 10000000000000000000 + CovenantCoinBalance: 10000000000000000000 + - Address: 8d7604acfdb391891a4c795f0939425b6d58bd50a81e579d15f06ecd381ad549 + StableCoinBalance: 10000000000000000000 + CovenantCoinBalance: 10000000000000000000 +KnownNodes: +- ID: 00000bef611d346c0cbe1beaa76e7f0ed705a194fdf9ac3a248ec70e9c198bf9 + Nonce: + a: 313283 + b: 0 + c: 0 + d: 0 + Addr: 127.0.0.1:3122 + PublicKey: "02c76216704d797c64c58bc11519fb68582e8e63de7e5b3b2dbbbe8733efe5fd24" + Role: Leader +- ID: 00000381d46fd6cf7742d7fb94e2422033af989c0e348b5781b3219599a3af35 + Nonce: + a: 478373 + b: 0 + c: 0 + d: 2305843009893772025 + Addr: 127.0.0.1:3121 + PublicKey: "02c76216704d797c64c58bc11519fb68582e8e63de7e5b3b2dbbbe8733efe5fd24" + Role: Follower +- ID: 000000172580063ded88e010556b0aca2851265be8845b1ef397e8fce6ab5582 + Nonce: + a: 259939 + b: 0 + c: 0 + d: 2305843012544226372 + Addr: 127.0.0.1:3120 + PublicKey: "02c76216704d797c64c58bc11519fb68582e8e63de7e5b3b2dbbbe8733efe5fd24" + Role: Follower +- ID: 0000000e930b108b13739215d0139275354e242b500392e48ddb5ae71eb2b1b9 + Role: Client + Addr: 0.0.0.0:15151 + DirectAddr: "" + PublicKey: 02c76216704d797c64c58bc11519fb68582e8e63de7e5b3b2dbbbe8733efe5fd24 + Nonce: + a: 8101741657 + b: 0 + c: 0 + d: 0 diff --git a/test/compatibility/node_bp_c/private.key b/test/compatibility/node_bp_c/private.key new file mode 100644 index 000000000..1815fe3ab --- /dev/null +++ b/test/compatibility/node_bp_c/private.key @@ -0,0 +1 @@ +MRjp4SP5mi5WWMdfRhDdrzEZo8iehyvnfDZej8Eko9Y8J68EaKofjci8yAtnZVtoP1S8XaghGUMHmFWH4C6eoqQJpi3PMv \ No newline at end of file diff --git a/test/compatibility/node_c/config.yaml b/test/compatibility/node_c/config.yaml index d1830a49a..04c8a9b61 100644 --- a/test/compatibility/node_c/config.yaml +++ b/test/compatibility/node_c/config.yaml @@ -56,6 +56,9 @@ BlockProducer: - Address: 9e1618775cceeb19f110e04fbc6c5bca6c8e4e9b116e193a42fe69bf602e7bcd StableCoinBalance: 10000000000000000000 CovenantCoinBalance: 10000000000000000000 + - Address: 8d7604acfdb391891a4c795f0939425b6d58bd50a81e579d15f06ecd381ad549 + StableCoinBalance: 10000000000000000000 + CovenantCoinBalance: 10000000000000000000 KnownNodes: - ID: 00000bef611d346c0cbe1beaa76e7f0ed705a194fdf9ac3a248ec70e9c198bf9 Nonce: diff --git a/test/compatibility/node_miner_0/config.yaml b/test/compatibility/node_miner_0/config.yaml index 382b3bd15..ee0fcd2c0 100644 --- a/test/compatibility/node_miner_0/config.yaml +++ b/test/compatibility/node_miner_0/config.yaml @@ -47,6 +47,9 @@ BlockProducer: - Address: 9e1618775cceeb19f110e04fbc6c5bca6c8e4e9b116e193a42fe69bf602e7bcd StableCoinBalance: 10000000000000000000 CovenantCoinBalance: 10000000000000000000 + - Address: 8d7604acfdb391891a4c795f0939425b6d58bd50a81e579d15f06ecd381ad549 + StableCoinBalance: 10000000000000000000 + CovenantCoinBalance: 10000000000000000000 Miner: UseTestMasterKey: true RootDir: "./data" diff --git a/test/compatibility/node_miner_1/config.yaml b/test/compatibility/node_miner_1/config.yaml index dc9b12c3d..c2693d2a0 100644 --- a/test/compatibility/node_miner_1/config.yaml +++ b/test/compatibility/node_miner_1/config.yaml @@ -47,6 +47,9 @@ BlockProducer: - Address: 9e1618775cceeb19f110e04fbc6c5bca6c8e4e9b116e193a42fe69bf602e7bcd StableCoinBalance: 10000000000000000000 CovenantCoinBalance: 10000000000000000000 + - Address: 8d7604acfdb391891a4c795f0939425b6d58bd50a81e579d15f06ecd381ad549 + StableCoinBalance: 10000000000000000000 + CovenantCoinBalance: 10000000000000000000 Miner: UseTestMasterKey: true RootDir: "./data" diff --git a/test/compatibility/node_miner_2/config.yaml b/test/compatibility/node_miner_2/config.yaml index d19615578..564c2bfdd 100644 --- a/test/compatibility/node_miner_2/config.yaml +++ b/test/compatibility/node_miner_2/config.yaml @@ -47,6 +47,9 @@ BlockProducer: - Address: 9e1618775cceeb19f110e04fbc6c5bca6c8e4e9b116e193a42fe69bf602e7bcd StableCoinBalance: 10000000000000000000 CovenantCoinBalance: 10000000000000000000 + - Address: 8d7604acfdb391891a4c795f0939425b6d58bd50a81e579d15f06ecd381ad549 + StableCoinBalance: 10000000000000000000 + CovenantCoinBalance: 10000000000000000000 Miner: UseTestMasterKey: true RootDir: "./data" diff --git a/test/compatibility/specific_old.sh b/test/compatibility/specific_old.sh index b1ec1e254..2adc8107c 100755 --- a/test/compatibility/specific_old.sh +++ b/test/compatibility/specific_old.sh @@ -34,9 +34,9 @@ esac cd ${TEST_WD} # start bp -nohup ${BPBIN} -config node_0/config.yaml >${LOGS_DIR}/bp0.log 2>&1 & -nohup ${BPBIN} -config node_1/config.yaml >${LOGS_DIR}/bp1.log 2>&1 & -nohup ${BPBIN} -config node_2/config.yaml >${LOGS_DIR}/bp2.log 2>&1 & +nohup ${BPBIN} -config node_0/config.yaml -log-level debug >${LOGS_DIR}/bp0.log 2>&1 & +nohup ${BPBIN} -config node_1/config.yaml -log-level debug >${LOGS_DIR}/bp1.log 2>&1 & +nohup ${BPBIN} -config node_2/config.yaml -log-level debug >${LOGS_DIR}/bp2.log 2>&1 & # wait bp start sleep 20 @@ -49,6 +49,16 @@ nohup ${MINERBIN} -config node_miner_2/config.yaml >${LOGS_DIR}/miner2.log 2>&1 # wait miner start sleep 20 +# use new client and bp_node_c node config to approve miners for public service +( + ${NEW_BIN_DIR}/cql rpc -config node_bp_c/config.yaml -bp -name 'MCC.AddTx' -wait-tx-confirm \ + -req '{"Tx": {"TxType": 13, "Miner": "ba0ba731c7a76ccef2c1170f42038f7e228dfb474ef0190dfe35d9a37911ed37", "Enabled": 1}}' + ${NEW_BIN_DIR}/cql rpc -config node_bp_c/config.yaml -bp -name 'MCC.AddTx' -wait-tx-confirm \ + -req '{"Tx": {"TxType": 13, "Miner": "1a7b0959bbd0d0ec529278a61c0056c277bffe75b2646e1699b46b10a90210be", "Enabled": 1}}' + ${NEW_BIN_DIR}/cql rpc -config node_bp_c/config.yaml -bp -name 'MCC.AddTx' -wait-tx-confirm \ + -req '{"Tx": {"TxType": 13, "Miner": "9235bc4130a2ed4e6c35ea189dab35198ebb105640bedb97dd5269cc80863b16", "Enabled": 1}}' +) || [[ "${test_case}" == "bp" ]] + ${CLIENTBIN} wallet -config node_c/config.yaml ${CLIENTBIN} create -config node_c/config.yaml -wait-tx-confirm -db-node 2 diff --git a/test/fuse/node_0/config.yaml b/test/fuse/node_0/config.yaml index 1144f6ace..bb2ef7a5b 100644 --- a/test/fuse/node_0/config.yaml +++ b/test/fuse/node_0/config.yaml @@ -56,6 +56,9 @@ BlockProducer: - Address: 9e1618775cceeb19f110e04fbc6c5bca6c8e4e9b116e193a42fe69bf602e7bcd StableCoinBalance: 1000000000 CovenantCoinBalance: 1000000000 + - Address: 8d7604acfdb391891a4c795f0939425b6d58bd50a81e579d15f06ecd381ad549 + StableCoinBalance: 10000000000000000000 + CovenantCoinBalance: 10000000000000000000 KnownNodes: - ID: 00000bef611d346c0cbe1beaa76e7f0ed705a194fdf9ac3a248ec70e9c198bf9 Nonce: diff --git a/test/fuse/node_1/config.yaml b/test/fuse/node_1/config.yaml index 8b9e5736a..dacd28ed8 100644 --- a/test/fuse/node_1/config.yaml +++ b/test/fuse/node_1/config.yaml @@ -56,6 +56,9 @@ BlockProducer: - Address: 9e1618775cceeb19f110e04fbc6c5bca6c8e4e9b116e193a42fe69bf602e7bcd StableCoinBalance: 1000000000 CovenantCoinBalance: 1000000000 + - Address: 8d7604acfdb391891a4c795f0939425b6d58bd50a81e579d15f06ecd381ad549 + StableCoinBalance: 10000000000000000000 + CovenantCoinBalance: 10000000000000000000 KnownNodes: - ID: 00000bef611d346c0cbe1beaa76e7f0ed705a194fdf9ac3a248ec70e9c198bf9 Nonce: diff --git a/test/fuse/node_2/config.yaml b/test/fuse/node_2/config.yaml index ad5e833b4..1f4c91f5d 100644 --- a/test/fuse/node_2/config.yaml +++ b/test/fuse/node_2/config.yaml @@ -56,6 +56,9 @@ BlockProducer: - Address: 9e1618775cceeb19f110e04fbc6c5bca6c8e4e9b116e193a42fe69bf602e7bcd StableCoinBalance: 1000000000 CovenantCoinBalance: 1000000000 + - Address: 8d7604acfdb391891a4c795f0939425b6d58bd50a81e579d15f06ecd381ad549 + StableCoinBalance: 10000000000000000000 + CovenantCoinBalance: 10000000000000000000 KnownNodes: - ID: 00000bef611d346c0cbe1beaa76e7f0ed705a194fdf9ac3a248ec70e9c198bf9 Nonce: diff --git a/test/integration/node_0/config.yaml b/test/integration/node_0/config.yaml index 73ff9c935..828e4c525 100644 --- a/test/integration/node_0/config.yaml +++ b/test/integration/node_0/config.yaml @@ -56,6 +56,9 @@ BlockProducer: - Address: 9e1618775cceeb19f110e04fbc6c5bca6c8e4e9b116e193a42fe69bf602e7bcd StableCoinBalance: 1000000000 CovenantCoinBalance: 1000000000 + - Address: 8d7604acfdb391891a4c795f0939425b6d58bd50a81e579d15f06ecd381ad549 + StableCoinBalance: 10000000000000000000 + CovenantCoinBalance: 10000000000000000000 KnownNodes: - ID: 00000bef611d346c0cbe1beaa76e7f0ed705a194fdf9ac3a248ec70e9c198bf9 Nonce: diff --git a/test/integration/node_1/config.yaml b/test/integration/node_1/config.yaml index d6089d9ea..fe429187f 100644 --- a/test/integration/node_1/config.yaml +++ b/test/integration/node_1/config.yaml @@ -56,6 +56,9 @@ BlockProducer: - Address: 9e1618775cceeb19f110e04fbc6c5bca6c8e4e9b116e193a42fe69bf602e7bcd StableCoinBalance: 1000000000 CovenantCoinBalance: 1000000000 + - Address: 8d7604acfdb391891a4c795f0939425b6d58bd50a81e579d15f06ecd381ad549 + StableCoinBalance: 10000000000000000000 + CovenantCoinBalance: 10000000000000000000 KnownNodes: - ID: 00000bef611d346c0cbe1beaa76e7f0ed705a194fdf9ac3a248ec70e9c198bf9 Nonce: diff --git a/test/integration/node_2/config.yaml b/test/integration/node_2/config.yaml index 213f6dc9a..15fd5a39e 100644 --- a/test/integration/node_2/config.yaml +++ b/test/integration/node_2/config.yaml @@ -56,6 +56,9 @@ BlockProducer: - Address: 9e1618775cceeb19f110e04fbc6c5bca6c8e4e9b116e193a42fe69bf602e7bcd StableCoinBalance: 1000000000 CovenantCoinBalance: 1000000000 + - Address: 8d7604acfdb391891a4c795f0939425b6d58bd50a81e579d15f06ecd381ad549 + StableCoinBalance: 10000000000000000000 + CovenantCoinBalance: 10000000000000000000 KnownNodes: - ID: 00000bef611d346c0cbe1beaa76e7f0ed705a194fdf9ac3a248ec70e9c198bf9 Nonce: diff --git a/test/integration/node_miner_0/config.yaml b/test/integration/node_miner_0/config.yaml index 049c65bf3..0a2926969 100644 --- a/test/integration/node_miner_0/config.yaml +++ b/test/integration/node_miner_0/config.yaml @@ -48,6 +48,9 @@ BlockProducer: - Address: 9e1618775cceeb19f110e04fbc6c5bca6c8e4e9b116e193a42fe69bf602e7bcd StableCoinBalance: 1000000000 CovenantCoinBalance: 1000000000 + - Address: 8d7604acfdb391891a4c795f0939425b6d58bd50a81e579d15f06ecd381ad549 + StableCoinBalance: 10000000000000000000 + CovenantCoinBalance: 10000000000000000000 Miner: UseTestMasterKey: true RootDir: "./data" diff --git a/test/integration/node_miner_1/config.yaml b/test/integration/node_miner_1/config.yaml index 1595d42e6..5f9362a98 100644 --- a/test/integration/node_miner_1/config.yaml +++ b/test/integration/node_miner_1/config.yaml @@ -48,6 +48,9 @@ BlockProducer: - Address: 9e1618775cceeb19f110e04fbc6c5bca6c8e4e9b116e193a42fe69bf602e7bcd StableCoinBalance: 1000000000 CovenantCoinBalance: 1000000000 + - Address: 8d7604acfdb391891a4c795f0939425b6d58bd50a81e579d15f06ecd381ad549 + StableCoinBalance: 10000000000000000000 + CovenantCoinBalance: 10000000000000000000 Miner: UseTestMasterKey: true RootDir: "./data" diff --git a/test/integration/node_miner_2/config.yaml b/test/integration/node_miner_2/config.yaml index 7afdaf200..65236f5e1 100644 --- a/test/integration/node_miner_2/config.yaml +++ b/test/integration/node_miner_2/config.yaml @@ -48,6 +48,9 @@ BlockProducer: - Address: 9e1618775cceeb19f110e04fbc6c5bca6c8e4e9b116e193a42fe69bf602e7bcd StableCoinBalance: 1000000000 CovenantCoinBalance: 1000000000 + - Address: 8d7604acfdb391891a4c795f0939425b6d58bd50a81e579d15f06ecd381ad549 + StableCoinBalance: 10000000000000000000 + CovenantCoinBalance: 10000000000000000000 Miner: UseTestMasterKey: true RootDir: "./data" diff --git a/test/mirror/node_0/config.yaml b/test/mirror/node_0/config.yaml index c07ee03a0..dada8ec9b 100644 --- a/test/mirror/node_0/config.yaml +++ b/test/mirror/node_0/config.yaml @@ -59,6 +59,9 @@ BlockProducer: - Address: e4e1628477a17c969f3f915f4bc7c059c3fbcbaf37855bc55a811465ea2480af StableCoinBalance: 1000000000 CovenantCoinBalance: 1000000000 + - Address: 8d7604acfdb391891a4c795f0939425b6d58bd50a81e579d15f06ecd381ad549 + StableCoinBalance: 10000000000000000000 + CovenantCoinBalance: 10000000000000000000 KnownNodes: - ID: 00000bef611d346c0cbe1beaa76e7f0ed705a194fdf9ac3a248ec70e9c198bf9 Nonce: diff --git a/test/mirror/node_1/config.yaml b/test/mirror/node_1/config.yaml index c8ff6f4b7..b86f34e13 100644 --- a/test/mirror/node_1/config.yaml +++ b/test/mirror/node_1/config.yaml @@ -59,6 +59,9 @@ BlockProducer: - Address: e4e1628477a17c969f3f915f4bc7c059c3fbcbaf37855bc55a811465ea2480af StableCoinBalance: 1000000000 CovenantCoinBalance: 1000000000 + - Address: 8d7604acfdb391891a4c795f0939425b6d58bd50a81e579d15f06ecd381ad549 + StableCoinBalance: 10000000000000000000 + CovenantCoinBalance: 10000000000000000000 KnownNodes: - ID: 00000bef611d346c0cbe1beaa76e7f0ed705a194fdf9ac3a248ec70e9c198bf9 Nonce: diff --git a/test/mirror/node_2/config.yaml b/test/mirror/node_2/config.yaml index a9c59994e..802806643 100644 --- a/test/mirror/node_2/config.yaml +++ b/test/mirror/node_2/config.yaml @@ -59,6 +59,9 @@ BlockProducer: - Address: e4e1628477a17c969f3f915f4bc7c059c3fbcbaf37855bc55a811465ea2480af StableCoinBalance: 1000000000 CovenantCoinBalance: 1000000000 + - Address: 8d7604acfdb391891a4c795f0939425b6d58bd50a81e579d15f06ecd381ad549 + StableCoinBalance: 10000000000000000000 + CovenantCoinBalance: 10000000000000000000 KnownNodes: - ID: 00000bef611d346c0cbe1beaa76e7f0ed705a194fdf9ac3a248ec70e9c198bf9 Nonce: diff --git a/test/observation/node_0/config.yaml b/test/observation/node_0/config.yaml index 025952e39..216cbe532 100644 --- a/test/observation/node_0/config.yaml +++ b/test/observation/node_0/config.yaml @@ -59,6 +59,9 @@ BlockProducer: - Address: e4e1628477a17c969f3f915f4bc7c059c3fbcbaf37855bc55a811465ea2480af StableCoinBalance: 1000000000 CovenantCoinBalance: 1000000000 + - Address: 8d7604acfdb391891a4c795f0939425b6d58bd50a81e579d15f06ecd381ad549 + StableCoinBalance: 10000000000000000000 + CovenantCoinBalance: 10000000000000000000 KnownNodes: - ID: 00000bef611d346c0cbe1beaa76e7f0ed705a194fdf9ac3a248ec70e9c198bf9 Nonce: diff --git a/test/observation/node_1/config.yaml b/test/observation/node_1/config.yaml index 6363edd9a..697eba1aa 100644 --- a/test/observation/node_1/config.yaml +++ b/test/observation/node_1/config.yaml @@ -59,6 +59,9 @@ BlockProducer: - Address: e4e1628477a17c969f3f915f4bc7c059c3fbcbaf37855bc55a811465ea2480af StableCoinBalance: 1000000000 CovenantCoinBalance: 1000000000 + - Address: 8d7604acfdb391891a4c795f0939425b6d58bd50a81e579d15f06ecd381ad549 + StableCoinBalance: 10000000000000000000 + CovenantCoinBalance: 10000000000000000000 KnownNodes: - ID: 00000bef611d346c0cbe1beaa76e7f0ed705a194fdf9ac3a248ec70e9c198bf9 Nonce: diff --git a/test/observation/node_2/config.yaml b/test/observation/node_2/config.yaml index 7966ad7a8..c05dee13f 100644 --- a/test/observation/node_2/config.yaml +++ b/test/observation/node_2/config.yaml @@ -59,6 +59,9 @@ BlockProducer: - Address: e4e1628477a17c969f3f915f4bc7c059c3fbcbaf37855bc55a811465ea2480af StableCoinBalance: 1000000000 CovenantCoinBalance: 1000000000 + - Address: 8d7604acfdb391891a4c795f0939425b6d58bd50a81e579d15f06ecd381ad549 + StableCoinBalance: 10000000000000000000 + CovenantCoinBalance: 10000000000000000000 KnownNodes: - ID: 00000bef611d346c0cbe1beaa76e7f0ed705a194fdf9ac3a248ec70e9c198bf9 Nonce: diff --git a/types/account.go b/types/account.go index c0fa01172..f66fff6ca 100644 --- a/types/account.go +++ b/types/account.go @@ -26,7 +26,7 @@ import ( ) //go:generate hsp -//hsp:ignore PermStat +//hsp:ignore PermStat SQLChainProfile MinerInfo UserArrears SQLChainUser ProviderProfile // SQLChainRole defines roles of account in a SQLChain. type SQLChainRole byte @@ -277,7 +277,9 @@ type SQLChainProfile struct { Owner proto.AccountAddress // first miner in the list is leader - Miners []*MinerInfo + // last ones are standby nodes if standby is enabled + Miners []*MinerInfo + StandbyMiners []*MinerInfo Users []*SQLChainUser @@ -288,15 +290,17 @@ type SQLChainProfile struct { // ProviderProfile defines a provider list. type ProviderProfile struct { - Provider proto.AccountAddress - Space uint64 // reserved storage space in bytes - Memory uint64 // reserved memory in bytes - LoadAvgPerCPU float64 // max loadAvg15 per CPU - TargetUser []proto.AccountAddress - Deposit uint64 // default 10 Particle - GasPrice uint64 - TokenType TokenType // default Particle - NodeID proto.NodeID + Provider proto.AccountAddress + Space uint64 // reserved storage space in bytes + Memory uint64 // reserved memory in bytes + LoadAvgPerCPU float64 // max loadAvg15 per CPU + TargetUser []proto.AccountAddress + Deposit uint64 // default 10 Particle + GasPrice uint64 + TokenType TokenType // default Particle + NodeID proto.NodeID + AllowPublicService bool // default not allowed + IsConsumed bool // default not consumed } // Account store its balance, and other mate data. diff --git a/types/account_gen.go b/types/account_gen.go index 320d3ebd0..ce5e9ccf8 100644 --- a/types/account_gen.go +++ b/types/account_gen.go @@ -36,59 +36,6 @@ func (z *Account) Msgsize() (s int) { return } -// MarshalHash marshals for hash -func (z *MinerInfo) MarshalHash() (o []byte, err error) { - var b []byte - o = hsp.Require(b, z.Msgsize()) - // map header, size 9 - o = append(o, 0x89) - if oTemp, err := z.Address.MarshalHash(); err != nil { - return nil, err - } else { - o = hsp.AppendBytes(o, oTemp) - } - o = hsp.AppendUint64(o, z.Deposit) - o = hsp.AppendString(o, z.EncryptionKey) - o = hsp.AppendString(o, z.Name) - if oTemp, err := z.NodeID.MarshalHash(); err != nil { - return nil, err - } else { - o = hsp.AppendBytes(o, oTemp) - } - o = hsp.AppendUint64(o, z.PendingIncome) - o = hsp.AppendUint64(o, z.ReceivedIncome) - o = hsp.AppendInt32(o, int32(z.Status)) - o = hsp.AppendArrayHeader(o, uint32(len(z.UserArrears))) - for za0001 := range z.UserArrears { - if z.UserArrears[za0001] == nil { - o = hsp.AppendNil(o) - } else { - // map header, size 2 - o = append(o, 0x82) - if oTemp, err := z.UserArrears[za0001].User.MarshalHash(); err != nil { - return nil, err - } else { - o = hsp.AppendBytes(o, oTemp) - } - o = hsp.AppendUint64(o, z.UserArrears[za0001].Arrears) - } - } - return -} - -// Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message -func (z *MinerInfo) Msgsize() (s int) { - s = 1 + 8 + z.Address.Msgsize() + 8 + hsp.Uint64Size + 14 + hsp.StringPrefixSize + len(z.EncryptionKey) + 5 + hsp.StringPrefixSize + len(z.Name) + 7 + z.NodeID.Msgsize() + 14 + hsp.Uint64Size + 15 + hsp.Uint64Size + 7 + hsp.Int32Size + 12 + hsp.ArrayHeaderSize - for za0001 := range z.UserArrears { - if z.UserArrears[za0001] == nil { - s += hsp.NilSize - } else { - s += 1 + 5 + z.UserArrears[za0001].User.Msgsize() + 8 + hsp.Uint64Size - } - } - return -} - // MarshalHash marshals for hash func (z *ProviderProfile) MarshalHash() (o []byte, err error) { var b []byte @@ -136,89 +83,6 @@ func (z *ProviderProfile) Msgsize() (s int) { return } -// MarshalHash marshals for hash -func (z *SQLChainProfile) MarshalHash() (o []byte, err error) { - var b []byte - o = hsp.Require(b, z.Msgsize()) - // map header, size 11 - o = append(o, 0x8b) - if oTemp, err := z.Address.MarshalHash(); err != nil { - return nil, err - } else { - o = hsp.AppendBytes(o, oTemp) - } - o = hsp.AppendBytes(o, z.EncodedGenesis) - o = hsp.AppendUint64(o, z.GasPrice) - if oTemp, err := z.ID.MarshalHash(); err != nil { - return nil, err - } else { - o = hsp.AppendBytes(o, oTemp) - } - o = hsp.AppendUint32(o, z.LastUpdatedHeight) - if oTemp, err := z.Meta.MarshalHash(); err != nil { - return nil, err - } else { - o = hsp.AppendBytes(o, oTemp) - } - o = hsp.AppendArrayHeader(o, uint32(len(z.Miners))) - for za0001 := range z.Miners { - if z.Miners[za0001] == nil { - o = hsp.AppendNil(o) - } else { - if oTemp, err := z.Miners[za0001].MarshalHash(); err != nil { - return nil, err - } else { - o = hsp.AppendBytes(o, oTemp) - } - } - } - if oTemp, err := z.Owner.MarshalHash(); err != nil { - return nil, err - } else { - o = hsp.AppendBytes(o, oTemp) - } - o = hsp.AppendUint64(o, z.Period) - if oTemp, err := z.TokenType.MarshalHash(); err != nil { - return nil, err - } else { - o = hsp.AppendBytes(o, oTemp) - } - o = hsp.AppendArrayHeader(o, uint32(len(z.Users))) - for za0002 := range z.Users { - if z.Users[za0002] == nil { - o = hsp.AppendNil(o) - } else { - if oTemp, err := z.Users[za0002].MarshalHash(); err != nil { - return nil, err - } else { - o = hsp.AppendBytes(o, oTemp) - } - } - } - return -} - -// Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message -func (z *SQLChainProfile) Msgsize() (s int) { - s = 1 + 8 + z.Address.Msgsize() + 15 + hsp.BytesPrefixSize + len(z.EncodedGenesis) + 9 + hsp.Uint64Size + 3 + z.ID.Msgsize() + 18 + hsp.Uint32Size + 5 + z.Meta.Msgsize() + 7 + hsp.ArrayHeaderSize - for za0001 := range z.Miners { - if z.Miners[za0001] == nil { - s += hsp.NilSize - } else { - s += z.Miners[za0001].Msgsize() - } - } - s += 6 + z.Owner.Msgsize() + 7 + hsp.Uint64Size + 10 + z.TokenType.Msgsize() + 6 + hsp.ArrayHeaderSize - for za0002 := range z.Users { - if z.Users[za0002] == nil { - s += hsp.NilSize - } else { - s += z.Users[za0002].Msgsize() - } - } - return -} - // MarshalHash marshals for hash func (z SQLChainRole) MarshalHash() (o []byte, err error) { var b []byte @@ -233,50 +97,6 @@ func (z SQLChainRole) Msgsize() (s int) { return } -// MarshalHash marshals for hash -func (z *SQLChainUser) MarshalHash() (o []byte, err error) { - var b []byte - o = hsp.Require(b, z.Msgsize()) - // map header, size 6 - o = append(o, 0x86) - if oTemp, err := z.Address.MarshalHash(); err != nil { - return nil, err - } else { - o = hsp.AppendBytes(o, oTemp) - } - o = hsp.AppendUint64(o, z.AdvancePayment) - o = hsp.AppendUint64(o, z.Arrears) - o = hsp.AppendUint64(o, z.Deposit) - if z.Permission == nil { - o = hsp.AppendNil(o) - } else { - // map header, size 2 - o = append(o, 0x82) - o = hsp.AppendInt32(o, int32(z.Permission.Role)) - o = hsp.AppendArrayHeader(o, uint32(len(z.Permission.Patterns))) - for za0001 := range z.Permission.Patterns { - o = hsp.AppendString(o, z.Permission.Patterns[za0001]) - } - } - o = hsp.AppendInt32(o, int32(z.Status)) - return -} - -// Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message -func (z *SQLChainUser) Msgsize() (s int) { - s = 1 + 8 + z.Address.Msgsize() + 15 + hsp.Uint64Size + 8 + hsp.Uint64Size + 8 + hsp.Uint64Size + 11 - if z.Permission == nil { - s += hsp.NilSize - } else { - s += 1 + 5 + hsp.Int32Size + 9 + hsp.ArrayHeaderSize - for za0001 := range z.Permission.Patterns { - s += hsp.StringPrefixSize + len(z.Permission.Patterns[za0001]) - } - } - s += 7 + hsp.Int32Size - return -} - // MarshalHash marshals for hash func (z Status) MarshalHash() (o []byte, err error) { var b []byte @@ -291,27 +111,6 @@ func (z Status) Msgsize() (s int) { return } -// MarshalHash marshals for hash -func (z *UserArrears) MarshalHash() (o []byte, err error) { - var b []byte - o = hsp.Require(b, z.Msgsize()) - // map header, size 2 - o = append(o, 0x82) - o = hsp.AppendUint64(o, z.Arrears) - if oTemp, err := z.User.MarshalHash(); err != nil { - return nil, err - } else { - o = hsp.AppendBytes(o, oTemp) - } - return -} - -// Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message -func (z *UserArrears) Msgsize() (s int) { - s = 1 + 8 + hsp.Uint64Size + 5 + z.User.Msgsize() - return -} - // MarshalHash marshals for hash func (z *UserPermission) MarshalHash() (o []byte, err error) { var b []byte diff --git a/types/account_gen_test.go b/types/account_gen_test.go index 388a19ddb..615f7c7b3 100644 --- a/types/account_gen_test.go +++ b/types/account_gen_test.go @@ -46,43 +46,6 @@ func BenchmarkAppendMsgAccount(b *testing.B) { } } -func TestMarshalHashMinerInfo(t *testing.T) { - v := MinerInfo{} - binary.Read(rand.Reader, binary.BigEndian, &v) - bts1, err := v.MarshalHash() - if err != nil { - t.Fatal(err) - } - bts2, err := v.MarshalHash() - if err != nil { - t.Fatal(err) - } - if !bytes.Equal(bts1, bts2) { - t.Fatal("hash not stable") - } -} - -func BenchmarkMarshalHashMinerInfo(b *testing.B) { - v := MinerInfo{} - b.ReportAllocs() - b.ResetTimer() - for i := 0; i < b.N; i++ { - v.MarshalHash() - } -} - -func BenchmarkAppendMsgMinerInfo(b *testing.B) { - v := MinerInfo{} - bts := make([]byte, 0, v.Msgsize()) - bts, _ = v.MarshalHash() - b.SetBytes(int64(len(bts))) - b.ReportAllocs() - b.ResetTimer() - for i := 0; i < b.N; i++ { - bts, _ = v.MarshalHash() - } -} - func TestMarshalHashProviderProfile(t *testing.T) { v := ProviderProfile{} binary.Read(rand.Reader, binary.BigEndian, &v) @@ -120,117 +83,6 @@ func BenchmarkAppendMsgProviderProfile(b *testing.B) { } } -func TestMarshalHashSQLChainProfile(t *testing.T) { - v := SQLChainProfile{} - binary.Read(rand.Reader, binary.BigEndian, &v) - bts1, err := v.MarshalHash() - if err != nil { - t.Fatal(err) - } - bts2, err := v.MarshalHash() - if err != nil { - t.Fatal(err) - } - if !bytes.Equal(bts1, bts2) { - t.Fatal("hash not stable") - } -} - -func BenchmarkMarshalHashSQLChainProfile(b *testing.B) { - v := SQLChainProfile{} - b.ReportAllocs() - b.ResetTimer() - for i := 0; i < b.N; i++ { - v.MarshalHash() - } -} - -func BenchmarkAppendMsgSQLChainProfile(b *testing.B) { - v := SQLChainProfile{} - bts := make([]byte, 0, v.Msgsize()) - bts, _ = v.MarshalHash() - b.SetBytes(int64(len(bts))) - b.ReportAllocs() - b.ResetTimer() - for i := 0; i < b.N; i++ { - bts, _ = v.MarshalHash() - } -} - -func TestMarshalHashSQLChainUser(t *testing.T) { - v := SQLChainUser{} - binary.Read(rand.Reader, binary.BigEndian, &v) - bts1, err := v.MarshalHash() - if err != nil { - t.Fatal(err) - } - bts2, err := v.MarshalHash() - if err != nil { - t.Fatal(err) - } - if !bytes.Equal(bts1, bts2) { - t.Fatal("hash not stable") - } -} - -func BenchmarkMarshalHashSQLChainUser(b *testing.B) { - v := SQLChainUser{} - b.ReportAllocs() - b.ResetTimer() - for i := 0; i < b.N; i++ { - v.MarshalHash() - } -} - -func BenchmarkAppendMsgSQLChainUser(b *testing.B) { - v := SQLChainUser{} - bts := make([]byte, 0, v.Msgsize()) - bts, _ = v.MarshalHash() - b.SetBytes(int64(len(bts))) - b.ReportAllocs() - b.ResetTimer() - for i := 0; i < b.N; i++ { - bts, _ = v.MarshalHash() - } -} - -func TestMarshalHashUserArrears(t *testing.T) { - v := UserArrears{} - binary.Read(rand.Reader, binary.BigEndian, &v) - bts1, err := v.MarshalHash() - if err != nil { - t.Fatal(err) - } - bts2, err := v.MarshalHash() - if err != nil { - t.Fatal(err) - } - if !bytes.Equal(bts1, bts2) { - t.Fatal("hash not stable") - } -} - -func BenchmarkMarshalHashUserArrears(b *testing.B) { - v := UserArrears{} - b.ReportAllocs() - b.ResetTimer() - for i := 0; i < b.N; i++ { - v.MarshalHash() - } -} - -func BenchmarkAppendMsgUserArrears(b *testing.B) { - v := UserArrears{} - bts := make([]byte, 0, v.Msgsize()) - bts, _ = v.MarshalHash() - b.SetBytes(int64(len(bts))) - b.ReportAllocs() - b.ResetTimer() - for i := 0; i < b.N; i++ { - bts, _ = v.MarshalHash() - } -} - func TestMarshalHashUserPermission(t *testing.T) { v := UserPermission{} binary.Read(rand.Reader, binary.BigEndian, &v) diff --git a/types/init_service_type.go b/types/init_service_type.go index 5a94439df..f9384a7af 100644 --- a/types/init_service_type.go +++ b/types/init_service_type.go @@ -40,6 +40,8 @@ type ResourceMeta struct { UseEventualConsistency bool // use eventual consistency replication if enabled ConsistencyLevel float64 // customized strong consistency level IsolationLevel int // customized isolation level + StandbyNode uint16 // standby node count for recovery + Version int32 `hsp:"v,version"` // hsp version field } // ServiceInstance defines single instance to be initialized. diff --git a/types/init_service_type_gen.go b/types/init_service_type_gen.go index dcb38de3c..b262192cd 100644 --- a/types/init_service_type_gen.go +++ b/types/init_service_type_gen.go @@ -3,6 +3,8 @@ package types // Code generated by github.com/CovenantSQL/HashStablePack DO NOT EDIT. import ( + herr "errors" + hsp "github.com/CovenantSQL/HashStablePack/marshalhash" ) @@ -86,38 +88,50 @@ func (z *InitServiceResponseHeader) Msgsize() (s int) { return } +var hspVersionsResourceMeta = []string{ + "oldver", + "45c9f0", +} + +// HSPCurrentVersion returns current struct version +func (z *ResourceMeta) HSPCurrentVersion() int { + return int(z.Version) +} + +// HSPMaxVersion returns max struct version +func (z *ResourceMeta) HSPMaxVersion() int { + return 1 +} + +// HSPDefaultVersion returns default struct version +func (z *ResourceMeta) HSPDefaultVersion() int { + return 1 +} + // MarshalHash marshals for hash func (z *ResourceMeta) MarshalHash() (o []byte, err error) { - var b []byte - o = hsp.Require(b, z.Msgsize()) - // map header, size 9 - o = append(o, 0x89) - o = hsp.AppendFloat64(o, z.ConsistencyLevel) - o = hsp.AppendString(o, z.EncryptionKey) - o = hsp.AppendInt(o, z.IsolationLevel) - o = hsp.AppendFloat64(o, z.LoadAvgPerCPU) - o = hsp.AppendUint64(o, z.Memory) - o = hsp.AppendUint16(o, z.Node) - o = hsp.AppendUint64(o, z.Space) - o = hsp.AppendArrayHeader(o, uint32(len(z.TargetMiners))) - for za0001 := range z.TargetMiners { - if oTemp, err := z.TargetMiners[za0001].MarshalHash(); err != nil { - return nil, err - } else { - o = hsp.AppendBytes(o, oTemp) - } + switch z.HSPCurrentVersion() { + case 0: + return z.MarshalHasholdver() + case 1: + return z.MarshalHash45c9f0() + default: + err = herr.New("invalid struct version") + return } - o = hsp.AppendBool(o, z.UseEventualConsistency) return } // Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message func (z *ResourceMeta) Msgsize() (s int) { - s = 1 + 17 + hsp.Float64Size + 14 + hsp.StringPrefixSize + len(z.EncryptionKey) + 15 + hsp.IntSize + 14 + hsp.Float64Size + 7 + hsp.Uint64Size + 5 + hsp.Uint16Size + 6 + hsp.Uint64Size + 13 + hsp.ArrayHeaderSize - for za0001 := range z.TargetMiners { - s += z.TargetMiners[za0001].Msgsize() + switch z.HSPCurrentVersion() { + case 0: + return z.Msgsizeoldver() + case 1: + return z.Msgsize45c9f0() + default: + return 0 } - s += 23 + hsp.BoolSize return } diff --git a/types/init_service_type_resourcemeta_45c9f0_gen.go b/types/init_service_type_resourcemeta_45c9f0_gen.go new file mode 100644 index 000000000..769377d22 --- /dev/null +++ b/types/init_service_type_resourcemeta_45c9f0_gen.go @@ -0,0 +1,44 @@ +package types + +// Code generated by github.com/CovenantSQL/HashStablePack DO NOT EDIT. + +import ( + hsp "github.com/CovenantSQL/HashStablePack/marshalhash" +) + +// MarshalHash45c9f0 marshals for hash +func (z *ResourceMeta) MarshalHash45c9f0() (o []byte, err error) { + var b []byte + o = hsp.Require(b, z.Msgsize45c9f0()) + // map header, size 11 + o = append(o, 0x8b) + o = hsp.AppendFloat64(o, z.ConsistencyLevel) + o = hsp.AppendString(o, z.EncryptionKey) + o = hsp.AppendInt(o, z.IsolationLevel) + o = hsp.AppendFloat64(o, z.LoadAvgPerCPU) + o = hsp.AppendUint64(o, z.Memory) + o = hsp.AppendUint16(o, z.Node) + o = hsp.AppendUint64(o, z.Space) + o = hsp.AppendUint16(o, z.StandbyNode) + o = hsp.AppendArrayHeader(o, uint32(len(z.TargetMiners))) + for za0001 := range z.TargetMiners { + if oTemp, err := z.TargetMiners[za0001].MarshalHash(); err != nil { + return nil, err + } else { + o = hsp.AppendBytes(o, oTemp) + } + } + o = hsp.AppendBool(o, z.UseEventualConsistency) + o = hsp.AppendInt32(o, z.Version) + return +} + +// Msgsize45c9f0 returns an upper bound estimate of the number of bytes occupied by the serialized message +func (z *ResourceMeta) Msgsize45c9f0() (s int) { + s = 1 + 17 + hsp.Float64Size + 14 + hsp.StringPrefixSize + len(z.EncryptionKey) + 15 + hsp.IntSize + 14 + hsp.Float64Size + 7 + hsp.Uint64Size + 5 + hsp.Uint16Size + 6 + hsp.Uint64Size + 10 + hsp.Uint16Size + 13 + hsp.ArrayHeaderSize + for za0001 := range z.TargetMiners { + s += z.TargetMiners[za0001].Msgsize() + } + s += 23 + hsp.BoolSize + 2 + hsp.Int32Size + return +} diff --git a/types/init_service_type_resourcemeta_45c9f0_gen_test.go b/types/init_service_type_resourcemeta_45c9f0_gen_test.go new file mode 100644 index 000000000..0d01fd2fe --- /dev/null +++ b/types/init_service_type_resourcemeta_45c9f0_gen_test.go @@ -0,0 +1,47 @@ +package types + +// Code generated by github.com/CovenantSQL/HashStablePack DO NOT EDIT. + +import ( + "bytes" + "crypto/rand" + "encoding/binary" + "testing" +) + +func TestMarshalHash45c9f0ResourceMeta(t *testing.T) { + v := ResourceMeta{} + binary.Read(rand.Reader, binary.BigEndian, &v) + bts1, err := v.MarshalHash45c9f0() + if err != nil { + t.Fatal(err) + } + bts2, err := v.MarshalHash45c9f0() + if err != nil { + t.Fatal(err) + } + if !bytes.Equal(bts1, bts2) { + t.Fatal("hash not stable") + } +} + +func BenchmarkMarshalHash45c9f0ResourceMeta(b *testing.B) { + v := ResourceMeta{} + b.ReportAllocs() + b.ResetTimer() + for i := 0; i < b.N; i++ { + v.MarshalHash45c9f0() + } +} + +func BenchmarkAppendMsg45c9f0ResourceMeta(b *testing.B) { + v := ResourceMeta{} + bts := make([]byte, 0, v.Msgsize45c9f0()) + bts, _ = v.MarshalHash45c9f0() + b.SetBytes(int64(len(bts))) + b.ReportAllocs() + b.ResetTimer() + for i := 0; i < b.N; i++ { + bts, _ = v.MarshalHash45c9f0() + } +} diff --git a/types/init_service_type_resourcemeta_oldver_gen.go b/types/init_service_type_resourcemeta_oldver_gen.go new file mode 100644 index 000000000..be55c28b1 --- /dev/null +++ b/types/init_service_type_resourcemeta_oldver_gen.go @@ -0,0 +1,42 @@ +package types + +// Code generated by github.com/CovenantSQL/HashStablePack DO NOT EDIT. + +import ( + hsp "github.com/CovenantSQL/HashStablePack/marshalhash" +) + +// MarshalHasholdver marshals for hash +func (z *ResourceMeta) MarshalHasholdver() (o []byte, err error) { + var b []byte + o = hsp.Require(b, z.Msgsize()) + + o = append(o, 0x89) + o = hsp.AppendFloat64(o, z.ConsistencyLevel) + o = hsp.AppendString(o, z.EncryptionKey) + o = hsp.AppendInt(o, z.IsolationLevel) + o = hsp.AppendFloat64(o, z.LoadAvgPerCPU) + o = hsp.AppendUint64(o, z.Memory) + o = hsp.AppendUint16(o, z.Node) + o = hsp.AppendUint64(o, z.Space) + o = hsp.AppendArrayHeader(o, uint32(len(z.TargetMiners))) + for za0001 := range z.TargetMiners { + if oTemp, err := z.TargetMiners[za0001].MarshalHash(); err != nil { + return nil, err + } else { + o = hsp.AppendBytes(o, oTemp) + } + } + o = hsp.AppendBool(o, z.UseEventualConsistency) + return +} + +// Msgsizeoldver returns an upper bound estimate of the number of bytes occupied by the serialized message +func (z *ResourceMeta) Msgsizeoldver() (s int) { + s = 1 + 17 + hsp.Float64Size + 14 + hsp.StringPrefixSize + len(z.EncryptionKey) + 15 + hsp.IntSize + 14 + hsp.Float64Size + 7 + hsp.Uint64Size + 5 + hsp.Uint16Size + 6 + hsp.Uint64Size + 13 + hsp.ArrayHeaderSize + for za0001 := range z.TargetMiners { + s += z.TargetMiners[za0001].Msgsize() + } + s += 23 + hsp.BoolSize + return +} diff --git a/types/init_service_type_resourcemeta_oldver_gen_test.go b/types/init_service_type_resourcemeta_oldver_gen_test.go new file mode 100644 index 000000000..480c32a88 --- /dev/null +++ b/types/init_service_type_resourcemeta_oldver_gen_test.go @@ -0,0 +1,47 @@ +package types + +// Code generated by github.com/CovenantSQL/HashStablePack DO NOT EDIT. + +import ( + "bytes" + "crypto/rand" + "encoding/binary" + "testing" +) + +func TestMarshalHasholdverResourceMeta(t *testing.T) { + v := ResourceMeta{} + binary.Read(rand.Reader, binary.BigEndian, &v) + bts1, err := v.MarshalHasholdver() + if err != nil { + t.Fatal(err) + } + bts2, err := v.MarshalHasholdver() + if err != nil { + t.Fatal(err) + } + if !bytes.Equal(bts1, bts2) { + t.Fatal("hash not stable") + } +} + +func BenchmarkMarshalHasholdverResourceMeta(b *testing.B) { + v := ResourceMeta{} + b.ReportAllocs() + b.ResetTimer() + for i := 0; i < b.N; i++ { + v.MarshalHasholdver() + } +} + +func BenchmarkAppendMsgoldverResourceMeta(b *testing.B) { + v := ResourceMeta{} + bts := make([]byte, 0, v.Msgsizeoldver()) + bts, _ = v.MarshalHasholdver() + b.SetBytes(int64(len(bts))) + b.ReportAllocs() + b.ResetTimer() + for i := 0; i < b.N; i++ { + bts, _ = v.MarshalHasholdver() + } +} diff --git a/types/set_public_miner.go b/types/set_public_miner.go new file mode 100644 index 000000000..567fff885 --- /dev/null +++ b/types/set_public_miner.go @@ -0,0 +1,74 @@ +/* + * Copyright 2019 The CovenantSQL Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package types + +import ( + pi "github.com/CovenantSQL/CovenantSQL/blockproducer/interfaces" + "github.com/CovenantSQL/CovenantSQL/crypto" + "github.com/CovenantSQL/CovenantSQL/crypto/asymmetric" + "github.com/CovenantSQL/CovenantSQL/crypto/verifier" + "github.com/CovenantSQL/CovenantSQL/proto" +) + +//go:generate hsp + +// SetPublicMinerHeader defines the miner register transaction header. +type SetPublicMinerHeader struct { + Miner proto.AccountAddress + Enabled uint8 + Nonce pi.AccountNonce +} + +// SetPublicMiner defines the miner register transaction. +type SetPublicMiner struct { + SetPublicMinerHeader + pi.TransactionTypeMixin + verifier.DefaultHashSignVerifierImpl +} + +// GetAccountNonce implements interfaces/Transaction.GetAccountNonce. +func (mr *SetPublicMinerHeader) GetAccountNonce() pi.AccountNonce { + return mr.Nonce +} + +// GetAccountAddress implements interfaces/Transaction.GetAccountAddress. +func (mr *SetPublicMiner) GetAccountAddress() proto.AccountAddress { + addr, _ := crypto.PubKeyHash(mr.Signee) + return addr +} + +// Sign implements interfaces/Transaction.Sign. +func (mr *SetPublicMiner) Sign(signer *asymmetric.PrivateKey) error { + return mr.DefaultHashSignVerifierImpl.Sign(&mr.SetPublicMinerHeader, signer) +} + +// Verify implements interfaces/Transaction.Verify. +func (mr *SetPublicMiner) Verify() error { + return mr.DefaultHashSignVerifierImpl.Verify(&mr.SetPublicMinerHeader) +} + +// NewSetPublicMiner returns new instance. +func NewSetPublicMiner(header *SetPublicMinerHeader) *SetPublicMiner { + return &SetPublicMiner{ + SetPublicMinerHeader: *header, + TransactionTypeMixin: *pi.NewTransactionTypeMixin(pi.TransactionTypeSetPublicMiner), + } +} + +func init() { + pi.RegisterTransaction(pi.TransactionTypeSetPublicMiner, (*SetPublicMiner)(nil)) +} diff --git a/types/set_public_miner_gen.go b/types/set_public_miner_gen.go new file mode 100644 index 000000000..07e8b3859 --- /dev/null +++ b/types/set_public_miner_gen.go @@ -0,0 +1,71 @@ +package types + +// Code generated by github.com/CovenantSQL/HashStablePack DO NOT EDIT. + +import ( + hsp "github.com/CovenantSQL/HashStablePack/marshalhash" +) + +// MarshalHash marshals for hash +func (z *SetPublicMiner) MarshalHash() (o []byte, err error) { + var b []byte + o = hsp.Require(b, z.Msgsize()) + // map header, size 3 + o = append(o, 0x83) + if oTemp, err := z.DefaultHashSignVerifierImpl.MarshalHash(); err != nil { + return nil, err + } else { + o = hsp.AppendBytes(o, oTemp) + } + // map header, size 3 + o = append(o, 0x83) + if oTemp, err := z.SetPublicMinerHeader.Miner.MarshalHash(); err != nil { + return nil, err + } else { + o = hsp.AppendBytes(o, oTemp) + } + o = hsp.AppendUint8(o, z.SetPublicMinerHeader.Enabled) + if oTemp, err := z.SetPublicMinerHeader.Nonce.MarshalHash(); err != nil { + return nil, err + } else { + o = hsp.AppendBytes(o, oTemp) + } + if oTemp, err := z.TransactionTypeMixin.MarshalHash(); err != nil { + return nil, err + } else { + o = hsp.AppendBytes(o, oTemp) + } + return +} + +// Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message +func (z *SetPublicMiner) Msgsize() (s int) { + s = 1 + 28 + z.DefaultHashSignVerifierImpl.Msgsize() + 21 + 1 + 6 + z.SetPublicMinerHeader.Miner.Msgsize() + 8 + hsp.Uint8Size + 6 + z.SetPublicMinerHeader.Nonce.Msgsize() + 21 + z.TransactionTypeMixin.Msgsize() + return +} + +// MarshalHash marshals for hash +func (z *SetPublicMinerHeader) MarshalHash() (o []byte, err error) { + var b []byte + o = hsp.Require(b, z.Msgsize()) + // map header, size 3 + o = append(o, 0x83) + o = hsp.AppendUint8(o, z.Enabled) + if oTemp, err := z.Miner.MarshalHash(); err != nil { + return nil, err + } else { + o = hsp.AppendBytes(o, oTemp) + } + if oTemp, err := z.Nonce.MarshalHash(); err != nil { + return nil, err + } else { + o = hsp.AppendBytes(o, oTemp) + } + return +} + +// Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message +func (z *SetPublicMinerHeader) Msgsize() (s int) { + s = 1 + 8 + hsp.Uint8Size + 6 + z.Miner.Msgsize() + 6 + z.Nonce.Msgsize() + return +} diff --git a/types/set_public_miner_gen_test.go b/types/set_public_miner_gen_test.go new file mode 100644 index 000000000..14415f26f --- /dev/null +++ b/types/set_public_miner_gen_test.go @@ -0,0 +1,84 @@ +package types + +// Code generated by github.com/CovenantSQL/HashStablePack DO NOT EDIT. + +import ( + "bytes" + "crypto/rand" + "encoding/binary" + "testing" +) + +func TestMarshalHashSetPublicMiner(t *testing.T) { + v := SetPublicMiner{} + binary.Read(rand.Reader, binary.BigEndian, &v) + bts1, err := v.MarshalHash() + if err != nil { + t.Fatal(err) + } + bts2, err := v.MarshalHash() + if err != nil { + t.Fatal(err) + } + if !bytes.Equal(bts1, bts2) { + t.Fatal("hash not stable") + } +} + +func BenchmarkMarshalHashSetPublicMiner(b *testing.B) { + v := SetPublicMiner{} + b.ReportAllocs() + b.ResetTimer() + for i := 0; i < b.N; i++ { + v.MarshalHash() + } +} + +func BenchmarkAppendMsgSetPublicMiner(b *testing.B) { + v := SetPublicMiner{} + bts := make([]byte, 0, v.Msgsize()) + bts, _ = v.MarshalHash() + b.SetBytes(int64(len(bts))) + b.ReportAllocs() + b.ResetTimer() + for i := 0; i < b.N; i++ { + bts, _ = v.MarshalHash() + } +} + +func TestMarshalHashSetPublicMinerHeader(t *testing.T) { + v := SetPublicMinerHeader{} + binary.Read(rand.Reader, binary.BigEndian, &v) + bts1, err := v.MarshalHash() + if err != nil { + t.Fatal(err) + } + bts2, err := v.MarshalHash() + if err != nil { + t.Fatal(err) + } + if !bytes.Equal(bts1, bts2) { + t.Fatal("hash not stable") + } +} + +func BenchmarkMarshalHashSetPublicMinerHeader(b *testing.B) { + v := SetPublicMinerHeader{} + b.ReportAllocs() + b.ResetTimer() + for i := 0; i < b.N; i++ { + v.MarshalHash() + } +} + +func BenchmarkAppendMsgSetPublicMinerHeader(b *testing.B) { + v := SetPublicMinerHeader{} + bts := make([]byte, 0, v.Msgsize()) + bts, _ = v.MarshalHash() + b.SetBytes(int64(len(bts))) + b.ReportAllocs() + b.ResetTimer() + for i := 0; i < b.N; i++ { + bts, _ = v.MarshalHash() + } +} diff --git a/xenomint/sqlite/xxx_test.go b/xenomint/sqlite/xxx_test.go index e7fe63df3..f225f789d 100644 --- a/xenomint/sqlite/xxx_test.go +++ b/xenomint/sqlite/xxx_test.go @@ -45,7 +45,7 @@ func setup() { rand.Seed(time.Now().UnixNano()) - if runtime.GOOS == "linux" { + if runtime.GOOS == "linux" || runtime.GOOS == "darwin" { if err = syscall.Getrlimit(syscall.RLIMIT_NOFILE, &lmt); err != nil { panic(err) } @@ -53,6 +53,9 @@ func setup() { panic("insufficient max RLIMIT_NOFILE") } lmt.Cur = lmt.Max + if runtime.GOOS == "darwin" && lmt.Cur > 10240 { + lmt.Cur = 10240 + } if err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &lmt); err != nil { panic(err) } diff --git a/xenomint/xxx_test.go b/xenomint/xxx_test.go index 07d053f2f..ac416c1a8 100644 --- a/xenomint/xxx_test.go +++ b/xenomint/xxx_test.go @@ -199,7 +199,7 @@ func setup() { rand.Seed(time.Now().UnixNano()) - if runtime.GOOS == "linux" { + if runtime.GOOS == "linux" || runtime.GOOS == "darwin" { // Set NOFILE limit if err = syscall.Getrlimit(syscall.RLIMIT_NOFILE, &lmt); err != nil { panic(err) @@ -208,6 +208,9 @@ func setup() { panic("insufficient max RLIMIT_NOFILE") } lmt.Cur = lmt.Max + if runtime.GOOS == "darwin" && lmt.Cur > 10240 { + lmt.Cur = 10240 + } if err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &lmt); err != nil { panic(err) }