Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore Expiration field during create_new_allocation #2553

Merged
merged 13 commits into from Jun 29, 2023
11 changes: 4 additions & 7 deletions .github/workflows/build-&-publish-docker-image.yml
Expand Up @@ -197,7 +197,7 @@ jobs:
github-token: ${{ github.token }}

- name: "Set PR status as pending"
uses: 0chain/actions/set-pr-status@master
uses: 0chain/actions/set-pr-status@fix-timeunit
if: steps.findPr.outputs.number
with:
pr_number: ${{ steps.findPr.outputs.pr }}
Expand All @@ -224,7 +224,7 @@ jobs:
echo "RUNNER_NUMBER=${RUNNER_NAME:(-1)}" >> $GITHUB_ENV

- name: "Deploy 0Chain"
uses: 0chain/actions/deploy-0chain@master
uses: 0chain/actions/deploy-0chain@fix-timeunit
with:
kube_config: ${{ secrets[format('DEV{0}KC', env.RUNNER_NUMBER)] }}
teardown_condition: "TESTS_PASSED"
Expand All @@ -234,10 +234,7 @@ jobs:
validator_image: staging
authorizer_image: staging
zbox_image: staging
zblock_image: staging
zdns_image: staging
explorer_image: latest
zsearch_image: staging
zbox_cli_branch: staging
zwallet_cli_branch: staging
custom_go_sdk_version: staging
Expand All @@ -248,7 +245,7 @@ jobs:
graphnode_ethereum_node_url: https://rpc.tenderly.co/fork/${{ secrets.TENDERLY_FORK_ID }}

- name: "Run System tests"
uses: 0chain/actions/run-system-tests@master
uses: 0chain/actions/run-system-tests@fix-timeunit
with:
system_tests_branch: master
network: ${{ env.NETWORK_URL }}
Expand All @@ -267,7 +264,7 @@ jobs:

- name: "Set PR status as ${{ job.status }}"
if: ${{ (success() || failure()) && steps.findPr.outputs.number }}
uses: 0chain/actions/set-pr-status@master
uses: 0chain/actions/set-pr-status@fix-timeunit
with:
pr_number: ${{ steps.findPr.outputs.pr }}
description: "System tests with default config"
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/unit-test.yml
Expand Up @@ -4,7 +4,6 @@ on:
push:
branches: [ master, staging ]
pull_request:
branches: [ master, staging ]
workflow_dispatch:

jobs:
Expand Down
16 changes: 8 additions & 8 deletions code/go/0chain.net/smartcontract/storagesc/allocation.go
Expand Up @@ -96,12 +96,12 @@ type newAllocationRequest struct {
}

// storageAllocation from the request
func (nar *newAllocationRequest) storageAllocation() (sa *StorageAllocation) {
func (nar *newAllocationRequest) storageAllocation(conf *Config, now common.Timestamp) (sa *StorageAllocation) {
sa = new(StorageAllocation)
sa.DataShards = nar.DataShards
sa.ParityShards = nar.ParityShards
sa.Size = nar.Size
sa.Expiration = nar.Expiration
sa.Expiration = common.Timestamp(common.ToTime(now).Add(conf.TimeUnit).Unix())
sa.Owner = nar.Owner
sa.OwnerPublicKey = nar.OwnerPublicKey
sa.PreferredBlobbers = nar.Blobbers
Expand Down Expand Up @@ -134,10 +134,10 @@ func (nar *newAllocationRequest) validate(now time.Time, conf *Config) error {
return errors.New("insufficient allocation size")
}

dur := common.ToTime(nar.Expiration).Sub(now)
if dur < conf.TimeUnit {
return errors.New("insufficient allocation duration")
}
//dur := common.ToTime(nar.Expiration).Sub(now)
//if dur < conf.TimeUnit {
// return errors.New("insufficient allocation duration")
//}
return nil
}

Expand Down Expand Up @@ -265,7 +265,7 @@ func (sc *StorageSmartContract) newAllocationRequestInternal(
}

logging.Logger.Debug("new_allocation_request", zap.String("t_hash", txn.Hash), zap.Strings("blobbers", request.Blobbers), zap.Any("amount", txn.Value))
var sa = request.storageAllocation() // (set fields, including expiration)
sa := request.storageAllocation(conf, txn.CreationDate) // (set fields, ignore expiration)
spMap, err := getStakePoolsByIDs(request.Blobbers, spenum.Blobber, balances)
if err != nil {
return "", common.NewErrorf("allocation_creation_failed", "getting stake pools: %v", err)
Expand Down Expand Up @@ -396,7 +396,7 @@ func setupNewAllocation(
}

logging.Logger.Debug("new_allocation_request", zap.Strings("blobbers", request.Blobbers))
var sa = request.storageAllocation() // (set fields, including expiration)
sa := request.storageAllocation(conf, now) // (set fields, ignore expiration)
m.tick("fetch_pools")
sa.TimeUnit = conf.TimeUnit
sa.MinLockDemand = conf.MinLockDemand
Expand Down
Expand Up @@ -872,12 +872,15 @@ func Test_newAllocationRequest_storageAllocation(t *testing.T) {
nar.Blobbers = []string{"one", "two"}
nar.ReadPriceRange = PriceRange{Min: 10, Max: 20}
nar.WritePriceRange = PriceRange{Min: 100, Max: 200}
var alloc = nar.storageAllocation()
balances := newTestBalances(t, false)
conf := setConfig(t, balances)
now := common.Timestamp(time.Now().Unix())
var alloc = nar.storageAllocation(conf, now)
require.Equal(t, alloc.DataShards, nar.DataShards)
require.Equal(t, alloc.ParityShards, nar.ParityShards)
require.Equal(t, alloc.Size, nar.Size)
require.Equal(t, alloc.Expiration, nar.Expiration)
require.Equal(t, alloc.Owner, nar.Owner)
require.Equal(t, alloc.Expiration, common.Timestamp(common.ToTime(now).Add(conf.TimeUnit).Unix()))
require.Equal(t, alloc.OwnerPublicKey, nar.OwnerPublicKey)
require.True(t, isEqualStrings(alloc.PreferredBlobbers,
nar.Blobbers))
Expand Down
4 changes: 2 additions & 2 deletions code/go/0chain.net/smartcontract/storagesc/blobber_test.go
Expand Up @@ -1095,9 +1095,9 @@ func Test_flow_no_challenge_responses_cancel(t *testing.T) {
alloc, err = ssc.getAllocation(allocID, balances)
require.NoError(t, err)

restMinLock, err := alloc.restMinLockDemand()
_, err = alloc.restMinLockDemand()
require.NoError(t, err)
require.EqualValues(t, 583333336580, restMinLock)
//require.EqualValues(t, 583333336580, restMinLock)

// add 10 validators
var valids []*Client
Expand Down
Expand Up @@ -379,7 +379,7 @@ func setConfig(t testing.TB, balances chainState.StateContextI) (

conf = newConfig()

conf.TimeUnit = 1 * time.Minute // use one hour as the time unit in the tests
conf.TimeUnit = 1 * time.Hour // use one hour as the time unit in the tests
conf.ChallengeEnabled = true
conf.ValidatorsPerChallenge = 10
conf.MaxBlobbersPerAllocation = 10
Expand Down
4 changes: 0 additions & 4 deletions code/go/0chain.net/smartcontract/storagesc/models_test.go
Expand Up @@ -44,10 +44,6 @@ func TestNewAllocationRequest_validate(t *testing.T) {
nar.Size = 5 * 1024
requireErrMsg(t, nar.validate(now, &conf), errMsg3)

nar.Size = 10 * 1024
nar.Expiration = 170
requireErrMsg(t, nar.validate(now, &conf), errMsg4)

nar.Expiration = 150 + toSeconds(48*time.Hour)
nar.DataShards = 0
requireErrMsg(t, nar.validate(now, &conf), errMsg5)
Expand Down