Skip to content

Commit

Permalink
Merge branch 'staging' into fix/refactor-zboxcore-mobilesdk-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
yash10019coder authored Dec 26, 2024
2 parents 33e1ec2 + 1a30cbd commit 6353377
Show file tree
Hide file tree
Showing 42 changed files with 614 additions and 202 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/system_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
uses: 0chain/actions/.github/workflows/manual_system_tests.yml@master
with:
gosdk_branch: ${{ github.ref_name }}
repo_snapshots_branch: fix/refactor-zboxcore
repo_snapshots_branch: ${{ github.event.inputs.repo_snapshots_branch }}
test_file_filter: ${{ github.event.inputs.test_file_filter }}
skip_tests: ${{ github.event.inputs.skip_tests }}
run_smoke_tests: ${{ github.event.inputs.run_smoke_tests }}
Expand Down
27 changes: 3 additions & 24 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,6 @@ jobs:
version: '1.7'
force: 'false'

- name: "Create Tenderly virtual testnet"
run: |
echo "TENDERLY_CREATION_INFO=$(curl -X POST \
-H "x-access-key: ${{ secrets.TENDERLY_SECRET }}" \
-H "Content-Type: application/json" \
-d '{"slug":"mainnet-dev-${{ env.RUNNER_NUMBER }}-${{ github.run_id }}","displayName":"mainnet-dev-${{ env.RUNNER_NUMBER }}-${{ github.run_id }}","description":"","visibility":"TEAM","tags":{"purpose":"development"},"networkConfig":{"networkId":"1","blockNumber":"18512782","chainConfig":{"chainId":"1"},"baseFeePerGas":"1"},"explorerConfig":{"enabled":false,"verificationVisibility":"bytecode"},"syncState":false}' \
https://api.tenderly.co/api/v1/account/zus_network/project/project/testnet/container)" >> $GITHUB_ENV
- name: "Parse Tenderly virtual testnet creation transaction result"
run: |
echo "TENDERLY_VIRTUAL_TESTNET_ID=$(echo '${{ env.TENDERLY_CREATION_INFO }}' | jq -r '.container.id')" >> $GITHUB_ENV
echo "TENDERLY_VIRTUAL_TESTNET_RPC_ID=$(echo '${{ env.TENDERLY_CREATION_INFO }}' | jq -r '.container.connectivityConfig.endpoints[0].id')" >> $GITHUB_ENV
- name: "Deploy 0Chain"
uses: 0chain/actions/deploy-0chain@master
with:
Expand All @@ -115,10 +102,10 @@ jobs:
teardown_condition: "TESTS_PASSED"
custom_go_sdk_version: ${{ env.CURRENT_BRANCH_HEAD }}
SUBGRAPH_API_URL: ${{ secrets.SUBGRAPH_API_URL }}
TENDERLY_VIRTUAL_TESTNET_RPC_ID: ${{ env.TENDERLY_VIRTUAL_TESTNET_RPC_ID }}
TENDERLY_VIRTUAL_TESTNET_RPC_ID: ""
graphnode_sc: ${{ secrets.GRAPHNODE_SC }}
graphnode_network: ${{ secrets.GRAPHNODE_NETWORK }}
graphnode_ethereum_node_url: https://virtual.mainnet.rpc.tenderly.co/${{ env.TENDERLY_VIRTUAL_TESTNET_RPC_ID }}
graphnode_ethereum_node_url: ""
svc_account_secret: ${{ secrets.SVC_ACCOUNT_SECRET }}

- name: "Run System tests"
Expand All @@ -134,19 +121,11 @@ jobs:
retry_failures: true
run_frontend_tests: true
run_smoke_tests: ${{ github.ref != 'refs/heads/staging' && github.base_ref != 'staging' && github.ref != 'refs/heads/master' && github.base_ref != 'master' }}
TENDERLY_VIRTUAL_TESTNET_RPC_ID: ${{ env.TENDERLY_VIRTUAL_TESTNET_RPC_ID }}
TENDERLY_VIRTUAL_TESTNET_RPC_ID: ""
DEVOPS_CHANNEL_WEBHOOK_URL: ${{ secrets.DEVOPS_CHANNEL_WEBHOOK_URL }}
S3_ACCESS_KEY: ${{ secrets.S3_ACCESS_KEY }}
S3_SECRET_KEY: ${{ secrets.S3_SECRET_KEY }}

- name: "Remove Tenderly virtual testnet"
if: always()
run: |
curl -X DELETE \
-H "x-access-key: ${{ secrets.TENDERLY_SECRET }}" \
-H "Content-Type: application/json" \
https://api.tenderly.co/api/v1/account/zus_network/project/project/testnet/container/${{ env.TENDERLY_VIRTUAL_TESTNET_ID }}
- name: "Set PR status as ${{ job.status }}"
if: ${{ (success() || failure()) && steps.findPr.outputs.number }}
uses: 0chain/actions/set-pr-status@master
Expand Down
3 changes: 1 addition & 2 deletions core/client/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func GetClient() *zcncrypto.Wallet {
// - fee: Preferred value for the transaction fee, just the first value is taken
func InitSDK(walletJSON string,
blockWorker, chainID, signatureScheme string,
nonce int64, isSplitWallet, addWallet bool,
nonce int64, addWallet bool,
options ...int) error {

if addWallet {
Expand Down Expand Up @@ -318,7 +318,6 @@ func InitSDK(walletJSON string,
MinSubmit: minSubmit,
ConfirmationChainLength: confirmationChainLength,
SharderConsensous: sharderConsensous,
IsSplitWallet: isSplitWallet,
})
if err != nil {
return err
Expand Down
10 changes: 4 additions & 6 deletions core/conf/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ import (

const (
// DefaultMinSubmit default value for min_submit
DefaultMinSubmit = 10
DefaultMinSubmit = 20
// DefaultMinConfirmation default value for min_confirmation
DefaultMinConfirmation = 10
// DefaultMaxTxnQuery default value for max_txn_query
DefaultMaxTxnQuery = 5
DefaultMaxTxnQuery = 10
// DefaultConfirmationChainLength default value for confirmation_chain_length
DefaultConfirmationChainLength = 3
// DefaultQuerySleepTime default value for query_sleep_time
DefaultQuerySleepTime = 5
DefaultQuerySleepTime = 1
// DefaultSharderConsensous default consensous to take make SCRestAPI calls
DefaultSharderConsensous = 3
)
Expand Down Expand Up @@ -78,8 +78,6 @@ type Config struct {
SharderConsensous int `json:"sharder_consensous"`
ZauthServer string `json:"zauth_server"`
V *viper.Viper `json:"-"`

IsSplitWallet bool `json:"is_split_wallet"`
}

// LoadConfigFile load and parse SDK Config from file
Expand Down Expand Up @@ -178,7 +176,7 @@ func LoadConfig(v Reader) (Config, error) {

cfg.SignatureScheme = v.GetString("signature_scheme")
cfg.ChainID = v.GetString("chain_id")
cfg.ZauthServer = v.GetString("zauth.server")
cfg.ZauthServer = v.GetString("zauth_server")

return cfg, nil
}
Expand Down
14 changes: 7 additions & 7 deletions core/conf/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func TestLoadConfig(t *testing.T) {
var mockDefaultReader = func() Reader {
reader := &mocks.Reader{}
reader.On("GetString", "block_worker").Return("http://127.0.0.1:9091/dns")
reader.On("GetString", "zauth.server").Return("http://127.0.0.1:8090/")
reader.On("GetString", "zauth_server").Return("http://127.0.0.1:8090/")
reader.On("GetInt", "min_submit").Return(0)
reader.On("GetInt", "min_confirmation").Return(0)
reader.On("GetInt", "max_txn_query").Return(0)
Expand Down Expand Up @@ -42,7 +42,7 @@ func TestLoadConfig(t *testing.T) {

reader := &mocks.Reader{}
reader.On("GetString", "block_worker").Return("")
reader.On("GetString", "zauth.server").Return("")
reader.On("GetString", "zauth_server").Return("")
reader.On("GetInt", "min_submit").Return(0)
reader.On("GetInt", "min_confirmation").Return(0)
reader.On("GetInt", "max_txn_query").Return(0)
Expand Down Expand Up @@ -77,7 +77,7 @@ func TestLoadConfig(t *testing.T) {
return mockDefaultReader()
},
run: func(r *require.Assertions, cfg Config) {
r.Equal(10, cfg.MinSubmit)
r.Equal(20, cfg.MinSubmit)
},
},
{
Expand All @@ -87,7 +87,7 @@ func TestLoadConfig(t *testing.T) {

reader := &mocks.Reader{}
reader.On("GetString", "block_worker").Return("https://127.0.0.1:9091/dns")
reader.On("GetString", "zauth.server").Return("http://127.0.0.1:8090/")
reader.On("GetString", "zauth_server").Return("http://127.0.0.1:8090/")
reader.On("GetInt", "min_submit").Return(101)
reader.On("GetInt", "min_confirmation").Return(0)
reader.On("GetInt", "max_txn_query").Return(0)
Expand Down Expand Up @@ -122,7 +122,7 @@ func TestLoadConfig(t *testing.T) {

reader := &mocks.Reader{}
reader.On("GetString", "block_worker").Return("https://127.0.0.1:9091/dns")
reader.On("GetString", "zauth.server").Return("http://127.0.0.1:8090/")
reader.On("GetString", "zauth_server").Return("http://127.0.0.1:8090/")
reader.On("GetInt", "min_submit").Return(0)
reader.On("GetInt", "min_confirmation").Return(101)
reader.On("GetInt", "max_txn_query").Return(0)
Expand All @@ -147,7 +147,7 @@ func TestLoadConfig(t *testing.T) {
return mockDefaultReader()
},
run: func(r *require.Assertions, cfg Config) {
r.Equal(5, cfg.QuerySleepTime)
r.Equal(1, cfg.QuerySleepTime)
},
}, {
name: "Test_Config_Max_Txn_Query_Less_Than_1",
Expand All @@ -157,7 +157,7 @@ func TestLoadConfig(t *testing.T) {
return mockDefaultReader()
},
run: func(r *require.Assertions, cfg Config) {
r.Equal(5, cfg.MaxTxnQuery)
r.Equal(10, cfg.MaxTxnQuery)
},
}, {
name: "Test_Config_Confirmation_Chain_Length_Less_Than_1",
Expand Down
8 changes: 7 additions & 1 deletion core/transaction/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -629,8 +629,10 @@ func SmartContractTxnValueFee(scAddress string, sn SmartContractTxnData,

sys.Sleep(querySleepTime)

var confirmationResponse string

for retries < cfg.MaxTxnQuery {
t, err = VerifyTransaction(txn.Hash)
t, confirmationResponse, err = VerifyTransactionWithRes(txn.Hash)
if err == nil {
break
}
Expand All @@ -657,6 +659,10 @@ func SmartContractTxnValueFee(scAddress string, sn SmartContractTxnData,
return t.Hash, t.TransactionOutput, t.TransactionNonce, t, errors.New("", t.TransactionOutput)
}

if t.TransactionType == TxnTypeSend {
t.TransactionOutput = confirmationResponse
}

return t.Hash, t.TransactionOutput, t.TransactionNonce, t, nil
}

Expand Down
2 changes: 1 addition & 1 deletion core/transaction/entity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestOptimisticVerificationLearning(t *testing.T) {
EthereumNode: "",
})
ov := NewOptimisticVerifier([]string{"https://dev.zus.network/sharder01", "https://dev.zus.network/sharder02"})
_, err := ov.VerifyTransactionOptimistic("a20360964c067b319d52b5cad71d771b0e1d2a80e76001da73009899b09ffa31")
_, _, err := ov.VerifyTransactionOptimistic("a20360964c067b319d52b5cad71d771b0e1d2a80e76001da73009899b09ffa31")

assert.NoError(t, err)

Expand Down
54 changes: 38 additions & 16 deletions core/transaction/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,10 @@ func NewOptimisticVerifier(sharders []string) *OptimisticVerifier {
}
}

func (v *OptimisticVerifier) VerifyTransactionOptimistic(txnHash string) (*Transaction, error) {
func (v *OptimisticVerifier) VerifyTransactionOptimistic(txnHash string) (*Transaction, string, error) {
cfg, err := conf.GetClientConfig()
if err != nil {

return nil, err
return nil, "", err
}

//refresh sharders
Expand All @@ -60,7 +59,7 @@ func (v *OptimisticVerifier) VerifyTransactionOptimistic(txnHash string) (*Trans
//amount of sharders to query
minNumConfirmation := int(math.Ceil(float64(cfg.MinConfirmation*len(v.sharders)) / 100))
if minNumConfirmation > len(v.sharders) {
return nil, errors.New("verify_optimistic", "wrong number of min_confirmations")
return nil, "", errors.New("verify_optimistic", "wrong number of min_confirmations")
}
shuffled := util.Shuffle(v.sharders)[:minNumConfirmation]

Expand All @@ -76,6 +75,7 @@ func (v *OptimisticVerifier) VerifyTransactionOptimistic(txnHash string) (*Trans
var url string
var chain []*RoundBlockHeader
var txn *Transaction
var confirmationResponse string
r := resty.New(v.options...).Then(func(req *http.Request, resp *http.Response, respBody []byte, cf context.CancelFunc, err error) error {
if err != nil { //network issue
return err
Expand Down Expand Up @@ -107,6 +107,15 @@ func (v *OptimisticVerifier) VerifyTransactionOptimistic(txnHash string) (*Trans
return err
}

// set objmap to confirmationResponse using json marshal
confirmationResponseByte, err := json.Marshal(map[string]map[string]json.RawMessage{
"confirmation": objmap,
})
if err != nil {
return err
}
confirmationResponse = string(confirmationResponseByte)

b := &RoundBlockHeader{}
err = json.Unmarshal(respBody, b)
if err != nil {
Expand Down Expand Up @@ -143,7 +152,7 @@ L:
}

if len(chain) == 0 {
return nil, errors.Newf("verify", "can't get confirmation after %v retries", retriesCount)
return nil, "", errors.Newf("verify", "can't get confirmation after %v retries", retriesCount)
}

//remove current sharder from the list to avoid building chain with it
Expand All @@ -157,10 +166,10 @@ L:

err = v.checkConfirmation(chain)
if err != nil {
return nil, err
return nil, "", err
}

return txn, err
return txn, confirmationResponse, err
}

func (v *OptimisticVerifier) checkConfirmation(chain []*RoundBlockHeader) error {
Expand Down Expand Up @@ -281,18 +290,23 @@ func validateBlockHash(b *RoundBlockHeader) error {
return nil
}

// VerifyTransaction query transaction status from sharders, and verify it by mininal confirmation
func VerifyTransaction(txnHash string) (*Transaction, error) {
txn, _, err := VerifyTransactionWithRes(txnHash)
return txn, err
}

// VerifyTransaction query transaction status from sharders, and verify it by mininal confirmation
func VerifyTransactionWithRes(txnHash string) (*Transaction, string, error) {
nodeClient, err := client.GetNode()
if err != nil {
return nil, err
return nil, "", err
}

sharders := nodeClient.Sharders().Healthy()

cfg, err := conf.GetClientConfig()
if err != nil {
return nil, err
return nil, "", err
}

if cfg.VerifyOptimistic {
Expand All @@ -304,18 +318,18 @@ func VerifyTransaction(txnHash string) (*Transaction, error) {
}

// VerifyTransaction query transaction status from sharders, and verify it by mininal confirmation
func VerifyTransactionTrusted(txnHash string, sharders []string) (*Transaction, error) {
func VerifyTransactionTrusted(txnHash string, sharders []string) (*Transaction, string, error) {

cfg, err := conf.GetClientConfig()
if err != nil {

return nil, err
return nil, "", err
}

numSharders := len(sharders)

if numSharders == 0 {
return nil, ErrNoAvailableSharder
return nil, "", ErrNoAvailableSharder
}

minNumConfirmation := int(math.Ceil(float64(cfg.MinConfirmation*numSharders) / 100))
Expand All @@ -338,6 +352,7 @@ func VerifyTransactionTrusted(txnHash string, sharders []string) (*Transaction,
numSuccess := 0

var retTxn *Transaction
var confirmationResponse string

//leave first item for ErrTooLessConfirmation
var msgList = make([]string, 1, numSharders)
Expand Down Expand Up @@ -393,6 +408,13 @@ func VerifyTransactionTrusted(txnHash string, sharders []string) (*Transaction,
}
if len(txn.Signature) > 0 {
retTxn = txn
confirmationResponseByte, err := json.Marshal(map[string]map[string]json.RawMessage{
"confirmation": objmap,
})
if err != nil {
return err
}
confirmationResponse = string(confirmationResponseByte)
}
numSuccess++

Expand Down Expand Up @@ -432,12 +454,12 @@ func VerifyTransactionTrusted(txnHash string, sharders []string) (*Transaction,

if numSuccess > 0 && numSuccess >= minNumConfirmation {
if retTxn == nil {
return nil, errors.Throw(ErrNoTxnDetail, strings.Join(msgList, "\r\n"))
return nil, "", errors.Throw(ErrNoTxnDetail, strings.Join(msgList, "\r\n"))
}
return retTxn, nil
return retTxn, confirmationResponse, nil
}

msgList[0] = fmt.Sprintf("min_confirmation is %v%%, but got %v/%v sharders", cfg.MinConfirmation, numSuccess, numSharders)
return nil, errors.Throw(ErrTooLessConfirmation, strings.Join(msgList, "\r\n"))
return nil, confirmationResponse, errors.Throw(ErrTooLessConfirmation, strings.Join(msgList, "\r\n"))

}
2 changes: 1 addition & 1 deletion core/zcncrypto/signature_scheme.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type KeyPair struct {
type Wallet struct {
ClientID string `json:"client_id"`
ClientKey string `json:"client_key"`
PeerPublicKey string `json:"peer_public_key"` // Peer public key exists only in split wallet
PeerPublicKey string `json:"peer_public_key"` // Peer public key exists only in split wallet for web only.
Keys []KeyPair `json:"keys"`
Mnemonic string `json:"mnemonics"`
Version string `json:"version"`
Expand Down
4 changes: 2 additions & 2 deletions mobilesdk/sdk/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func InitStorageSDK(clientJson string, configJson string) (*StorageSDK, error) {
configObj.BlockWorker,
configObj.ChainID,
configObj.SignatureScheme,
0, false, true); err != nil {
0, true); err != nil {
l.Logger.Error(err)
return nil, err
}
Expand Down Expand Up @@ -418,7 +418,7 @@ func (s *StorageSDK) UpdateAllocation(size int64, extend bool, allocationID stri
return "", errors.Errorf("int64 overflow in lock")
}

hash, _, err = sdk.UpdateAllocation(size, extend, allocationID, lock, "", "", "", "", false, &sdk.FileOptionsParameters{})
hash, _, err = sdk.UpdateAllocation(size, extend, allocationID, lock, "", "", "", "", "", false, &sdk.FileOptionsParameters{}, "")
return hash, err
}

Expand Down
Loading

0 comments on commit 6353377

Please sign in to comment.