Skip to content

Commit

Permalink
Use client ID as stake pool id (0chain#556)
Browse files Browse the repository at this point in the history
* Remove pool id param from GetMinerSCNodePool()

* Remove pool id params
  • Loading branch information
peterlimg authored Sep 20, 2022
1 parent 9b7f137 commit 85a1b96
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 109 deletions.
4 changes: 2 additions & 2 deletions docs/uml/stake pool unlock.puml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
participant "<size:20><&terminal></size> ./zbox sp-unlock" as cli
collections gosdk

cli -> gosdk: StakePoolUnlock(blobberID, poolID, fee)
cli -> gosdk: StakePoolUnlock(blobberID, fee)

gosdk -> gosdk: check initialized sdk
alt empty blobber id
Expand All @@ -11,6 +11,6 @@ end

gosdk -> gosdk: create stake pool request
gosdk -> gosdk: create smart contract txn data
gosdk -> gosdk: send smart contract txn value fee
gosdk -> gosdk: send smart contract txn value fee
gosdk -> cli: return result
@enduml
18 changes: 5 additions & 13 deletions zboxcore/sdk/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,13 +366,12 @@ func GetTotalStoredData() (map[string]int64, error) {
type stakePoolRequest struct {
ProviderType ProviderType `json:"provider_type,omitempty"`
ProviderID string `json:"provider_id,omitempty"`
PoolID string `json:"pool_id,omitempty"`
}

// StakePoolLock locks tokens lack in stake pool
func StakePoolLock(providerType ProviderType, providerID string, value, fee uint64) (poolID string, nonce int64, err error) {
func StakePoolLock(providerType ProviderType, providerID string, value, fee uint64) (hash string, nonce int64, err error) {
if !sdkInitialized {
return poolID, 0, sdkNotInitialized
return "", 0, sdkNotInitialized
}

if providerType == 0 {
Expand All @@ -386,13 +385,12 @@ func StakePoolLock(providerType ProviderType, providerID string, value, fee uint
spr := stakePoolRequest{
ProviderType: providerType,
ProviderID: providerID,
PoolID: "",
}
var sn = transaction.SmartContractTxnData{
Name: transaction.STORAGESC_STAKE_POOL_LOCK,
InputArgs: &spr,
}
poolID, _, nonce, _, err = smartContractTxnValueFee(sn, value, fee)
hash, _, nonce, _, err = smartContractTxnValueFee(sn, value, fee)
return
}

Expand All @@ -411,7 +409,7 @@ type StakePoolUnlockUnstake struct {
// future. The time is maximal time that can be lesser in some cases. To
// unlock tokens can't be unlocked now, wait the time and unlock them (call
// this function again).
func StakePoolUnlock(providerType ProviderType, providerID string, poolID string, fee uint64) (unstake bool, nonce int64, err error) {
func StakePoolUnlock(providerType ProviderType, providerID string, fee uint64) (unstake bool, nonce int64, err error) {
if !sdkInitialized {
return false, 0, sdkNotInitialized
}
Expand All @@ -424,14 +422,9 @@ func StakePoolUnlock(providerType ProviderType, providerID string, poolID string
return false, 0, errors.New("stake_pool_lock", "provider_id is required")
}

if poolID == "" {
return false, 0, errors.New("stake_pool_lock", "pool_id is required")
}

spr := stakePoolRequest{
ProviderType: providerType,
ProviderID: providerID,
PoolID: poolID,
}

var sn = transaction.SmartContractTxnData{
Expand Down Expand Up @@ -1209,15 +1202,14 @@ const (
ProviderAuthorizer
)

func CollectRewards(providerId, poolId string, providerType ProviderType) (string, int64, error) {
func CollectRewards(providerId string, providerType ProviderType) (string, int64, error) {
if !sdkInitialized {
return "", 0, sdkNotInitialized
}

var input = map[string]interface{}{
"provider_id": providerId,
"provider_type": providerType,
"pool_id": poolId,
}
var sn = transaction.SmartContractTxnData{
Name: transaction.STORAGESC_COLLECT_REWARD,
Expand Down
42 changes: 17 additions & 25 deletions zcncore/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,23 +131,23 @@ type TransactionCommon interface {
VestingAdd(ar *VestingAddRequest, value uint64) error

MinerSCLock(minerID string, lock uint64) error
MinerSCCollectReward(string, string, Provider) error
MinerSCCollectReward(providerID string, providerType Provider) error

StorageSCCollectReward(string, string, Provider) error
StorageSCCollectReward(providerID string, providerType Provider) error

FinalizeAllocation(allocID string, fee uint64) error
CancelAllocation(allocID string, fee uint64) error
CreateAllocation(car *CreateAllocationRequest, lock uint64, fee uint64) error //
CreateReadPool(fee uint64) error
ReadPoolLock(allocID string, blobberID string, duration int64, lock uint64, fee uint64) error
ReadPoolUnlock(poolID string, fee uint64) error
ReadPoolUnlock(fee uint64) error
StakePoolLock(blobberID string, lock uint64, fee uint64) error
StakePoolUnlock(blobberID string, poolID string, fee uint64) error
StakePoolUnlock(blobberID string, fee uint64) error
UpdateBlobberSettings(blobber *Blobber, fee uint64) error
UpdateValidatorSettings(validator *Validator, fee uint64) error
UpdateAllocation(allocID string, sizeDiff int64, expirationDiff int64, lock uint64, fee uint64) error
WritePoolLock(allocID string, blobberID string, duration int64, lock uint64, fee uint64) error
WritePoolUnlock(poolID string, fee uint64) error
WritePoolUnlock(allocID string, fee uint64) error

VestingUpdateConfig(*InputMap) error
MinerScUpdateConfig(*InputMap) error
Expand Down Expand Up @@ -352,10 +352,9 @@ func (t *Transaction) MinerSCLock(nodeID string, lock uint64) (err error) {
return
}

func (t *Transaction) MinerSCCollectReward(providerId, poolId string, providerType Provider) error {
func (t *Transaction) MinerSCCollectReward(providerId string, providerType Provider) error {
pr := &scCollectReward{
ProviderId: providerId,
PoolId: poolId,
ProviderType: int(providerType),
}
err := t.createSmartContractTxn(MinerSmartContractAddress,
Expand All @@ -368,10 +367,9 @@ func (t *Transaction) MinerSCCollectReward(providerId, poolId string, providerTy
return err
}

func (t *Transaction) StorageSCCollectReward(providerId, poolId string, providerType Provider) error {
func (t *Transaction) StorageSCCollectReward(providerId string, providerType Provider) error {
pr := &scCollectReward{
ProviderId: providerId,
PoolId: poolId,
ProviderType: int(providerType),
}
err := t.createSmartContractTxn(StorageSmartContractAddress,
Expand Down Expand Up @@ -482,14 +480,9 @@ func (t *Transaction) ReadPoolLock(allocID, blobberID string,
}

// ReadPoolUnlock for current user and given pool.
func (t *Transaction) ReadPoolUnlock(poolID string, fee uint64) (err error) {
type unlockRequest struct {
PoolID string `json:"pool_id"`
}
func (t *Transaction) ReadPoolUnlock(fee uint64) (err error) {
err = t.createSmartContractTxn(StorageSmartContractAddress,
transaction.STORAGESC_READ_POOL_UNLOCK, &unlockRequest{
PoolID: poolID,
}, 0)
transaction.STORAGESC_READ_POOL_UNLOCK, nil, 0)
if err != nil {
logging.Error(err)
return
Expand Down Expand Up @@ -522,17 +515,15 @@ func (t *Transaction) StakePoolLock(blobberID string, lock, fee uint64) (
}

// StakePoolUnlock by blobberID and poolID.
func (t *Transaction) StakePoolUnlock(blobberID, poolID string,
func (t *Transaction) StakePoolUnlock(blobberID string,
fee uint64) (err error) {

type stakePoolRequest struct {
BlobberID string `json:"blobber_id"`
PoolID string `json:"pool_id"`
}

var spr stakePoolRequest
spr.BlobberID = blobberID
spr.PoolID = poolID

err = t.createSmartContractTxn(StorageSmartContractAddress, transaction.STORAGESC_STAKE_POOL_UNLOCK, &spr, 0)
if err != nil {
Expand Down Expand Up @@ -613,16 +604,17 @@ func (t *Transaction) WritePoolLock(allocID, blobberID string, duration int64,
}

// WritePoolUnlock for current user and given pool.
func (t *Transaction) WritePoolUnlock(poolID string, fee uint64) (
func (t *Transaction) WritePoolUnlock(allocID string, fee uint64) (
err error) {

type unlockRequest struct {
PoolID string `json:"pool_id"`
var ur = struct {
AllocationID string `json:"allocation_id"`
} {
AllocationID: allocID,
}

err = t.createSmartContractTxn(StorageSmartContractAddress,
transaction.STORAGESC_WRITE_POOL_UNLOCK, &unlockRequest{
PoolID: poolID,
}, 0)
transaction.STORAGESC_WRITE_POOL_UNLOCK, &ur, 0)
if err != nil {
logging.Error(err)
return
Expand Down
12 changes: 5 additions & 7 deletions zcncore/transaction_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ type TransactionScheme interface {

// Miner SC

MinerSCUnlock(minerID, poolID string) error
MinerSCUnlock(minerID string) error
}


Expand Down Expand Up @@ -736,7 +736,6 @@ func (t *Transaction) VestingDelete(poolID string) (err error) {

type scCollectReward struct {
ProviderId string `json:"provider_id"`
PoolId string `json:"pool_id"`
ProviderType int `json:"provider_type"`
}

Expand All @@ -746,13 +745,12 @@ type MinerSCLock struct {

type MinerSCUnlock struct {
ID string `json:"id"`
PoolID string `json:"pool_id"`
}

func (t *Transaction) MinerSCUnlock(nodeID, poolID string) (err error) {
var mscul MinerSCUnlock
mscul.ID = nodeID
mscul.PoolID = poolID
func (t *Transaction) MinerSCUnlock(nodeID string) (err error) {
mscul := MinerSCUnlock {
ID: nodeID,
}

err = t.createSmartContractTxn(MinerSmartContractAddress,
transaction.MINERSC_UNLOCK, &mscul, 0)
Expand Down
29 changes: 10 additions & 19 deletions zcncore/transaction_mobile.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ type TransactionCommon interface {
VestingAdd(ar VestingAddRequest, value string) error

MinerSCLock(minerID string, lock string) error
MinerSCCollectReward(providerId string, poolId string, providerType int) error
StorageSCCollectReward(providerId, poolId string, providerType int) error
MinerSCCollectReward(providerId string, providerType int) error
StorageSCCollectReward(providerId string, providerType int) error

FinalizeAllocation(allocID string, fee string) error
CancelAllocation(allocID string, fee string) error
CreateAllocation(car *CreateAllocationRequest, lock, fee string) error //
CreateReadPool(fee string) error
ReadPoolLock(allocID string, blobberID string, duration int64, lock, fee string) error
ReadPoolUnlock(poolID string, fee string) error
ReadPoolUnlock(fee string) error
StakePoolLock(blobberID string, lock, fee string) error
StakePoolUnlock(blobberID string, poolID string, fee string) error
StakePoolUnlock(blobberID string, fee string) error
UpdateBlobberSettings(blobber Blobber, fee string) error
UpdateAllocation(allocID string, sizeDiff int64, expirationDiff int64, lock, fee string) error
WritePoolLock(allocID string, lock, fee string) error
Expand Down Expand Up @@ -469,10 +469,9 @@ func (t *Transaction) MinerSCLock(nodeID string, lock string) (err error) {
return
}

func (t *Transaction) MinerSCCollectReward(providerId, poolId string, providerType int) error {
func (t *Transaction) MinerSCCollectReward(providerId string, providerType int) error {
pr := &scCollectReward{
ProviderId: providerId,
PoolId: poolId,
ProviderType: providerType,
}

Expand All @@ -486,10 +485,9 @@ func (t *Transaction) MinerSCCollectReward(providerId, poolId string, providerTy
return err
}

func (t *Transaction) StorageSCCollectReward(providerId, poolId string, providerType int) error {
func (t *Transaction) StorageSCCollectReward(providerId string, providerType int) error {
pr := &scCollectReward{
ProviderId: providerId,
PoolId: poolId,
ProviderType: providerType,
}
err := t.createSmartContractTxn(StorageSmartContractAddress,
Expand Down Expand Up @@ -628,19 +626,14 @@ func (t *Transaction) ReadPoolLock(allocID, blobberID string,
}

// ReadPoolUnlock for current user and given pool.
func (t *Transaction) ReadPoolUnlock(poolID string, fee string) error {
func (t *Transaction) ReadPoolUnlock(fee string) error {
v, err := parseCoinStr(fee)
if err != nil {
return err
}

type unlockRequest struct {
PoolID string `json:"pool_id"`
}
err = t.createSmartContractTxn(StorageSmartContractAddress,
transaction.STORAGESC_READ_POOL_UNLOCK, &unlockRequest{
PoolID: poolID,
}, 0)
transaction.STORAGESC_READ_POOL_UNLOCK, nil, 0)
if err != nil {
logging.Error(err)
return err
Expand Down Expand Up @@ -680,21 +673,19 @@ func (t *Transaction) StakePoolLock(blobberID string, lock, fee string) error {
return nil
}

// StakePoolUnlock by blobberID and poolID.
func (t *Transaction) StakePoolUnlock(blobberID, poolID string, fee string) error {
// StakePoolUnlock by blobberID
func (t *Transaction) StakePoolUnlock(blobberID string, fee string) error {
v, err := parseCoinStr(fee)
if err != nil {
return err
}

type stakePoolRequest struct {
BlobberID string `json:"blobber_id"`
PoolID string `json:"pool_id"`
}

var spr stakePoolRequest
spr.BlobberID = blobberID
spr.PoolID = poolID

err = t.createSmartContractTxn(StorageSmartContractAddress, transaction.STORAGESC_STAKE_POOL_UNLOCK, &spr, 0)
if err != nil {
Expand Down
Loading

0 comments on commit 85a1b96

Please sign in to comment.