Skip to content

Commit

Permalink
Move fromAddress validation to validate.go
Browse files Browse the repository at this point in the history
  • Loading branch information
vreff committed Mar 8, 2023
1 parent 5b5b944 commit 28d0279
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 10 deletions.
12 changes: 2 additions & 10 deletions core/services/vrf/listener_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,12 +570,8 @@ func (lsn *listenerV2) processRequestsPerSubBatch(
}
}

fromAddresses := lsn.fromAddresses()
if len(fromAddresses) == 0 {
l.Errorw("No fromAddresses specified in VRF v2 job spec, please specify")
continue
}
// All fromAddresses passed to the VRFv2 job have the same KeySpecificMaxGasPriceWei value.
fromAddresses := lsn.fromAddresses()
maxGasPriceWei := lsn.cfg.KeySpecificMaxGasPriceWei(fromAddresses[0])

// Cases:
Expand Down Expand Up @@ -751,12 +747,8 @@ func (lsn *listenerV2) processRequestsPerSub(
}
}

fromAddresses := lsn.fromAddresses()
if len(fromAddresses) == 0 {
l.Errorw("No fromAddresses specified in VRF v2 job spec, please specify")
continue
}
// All fromAddresses passed to the VRFv2 job have the same KeySpecificMaxGasPriceWei value.
fromAddresses := lsn.fromAddresses()
maxGasPriceWei := lsn.cfg.KeySpecificMaxGasPriceWei(fromAddresses[0])
observeRequestSimDuration(lsn.job.Name.ValueOrZero(), lsn.job.ExternalJobID, v2, unfulfilled)
pipelines := lsn.runPipelines(ctx, l, maxGasPriceWei, unfulfilled)
Expand Down
4 changes: 4 additions & 0 deletions core/services/vrf/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ func ValidatedVRFSpec(tomlString string) (job.Job, error) {
return jb, errors.Wrap(ErrKeyNotSet, "batch coordinator address must be provided if batchFulfillmentEnabled = true")
}

if len(spec.FromAddresses) == 0 {
return jb, errors.Wrap(ErrKeyNotSet, "fromAddreses needs to have a non-zero length.")
}

if spec.BatchFulfillmentGasMultiplier <= 0 {
spec.BatchFulfillmentGasMultiplier = 1.15
}
Expand Down
52 changes: 52 additions & 0 deletions core/services/vrf/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ schemaVersion = 1
minIncomingConfirmations = 10
publicKey = "0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F8179800"
coordinatorAddress = "0xB3b7874F13387D44a3398D298B075B7A3505D8d4"
fromAddresses = ["0xD883a6A1C22fC4AbFE938a5aDF9B2Cc31b1BF18B"]
requestTimeout = "168h" # 7 days
chunkSize = 25
backoffInitialDelay = "1m"
Expand Down Expand Up @@ -53,6 +54,7 @@ decode_log->vrf->encode_tx->submit_tx
require.NoError(t, err)
require.NotNil(t, s.VRFSpec)
assert.Equal(t, uint32(10), s.VRFSpec.MinIncomingConfirmations)
assert.Equal(t, "0xD883a6A1C22fC4AbFE938a5aDF9B2Cc31b1BF18B", s.VRFSpec.FromAddresses[0].String())
assert.Equal(t, "0xB3b7874F13387D44a3398D298B075B7A3505D8d4", s.VRFSpec.CoordinatorAddress.String())
assert.Equal(t, "0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f8179800", s.VRFSpec.PublicKey.String())
require.Equal(t, 168*time.Hour, s.VRFSpec.RequestTimeout)
Expand All @@ -68,6 +70,7 @@ type = "vrf"
schemaVersion = 1
minIncomingConfirmations = 10
coordinatorAddress = "0xB3b7874F13387D44a3398D298B075B7A3505D8d4"
fromAddresses = ["0xD883a6A1C22fC4AbFE938a5aDF9B2Cc31b1BF18B"]
observationSource = """
decode_log [type=ethabidecodelog
abi="RandomnessRequest(bytes32 keyHash,uint256 seed,bytes32 indexed jobID,address sender,uint256 fee,bytes32 requestID)"
Expand All @@ -92,12 +95,49 @@ decode_log->vrf->encode_tx->submit_tx
require.True(t, errors.Is(ErrKeyNotSet, errors.Cause(err)))
},
},
{
name: "missing fromAddresses",
toml: `
type = "vrf"
schemaVersion = 1
minIncomingConfirmations = 10
publicKey = "0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F8179800"
coordinatorAddress = "0xB3b7874F13387D44a3398D298B075B7A3505D8d4"
requestTimeout = "168h" # 7 days
chunkSize = 25
backoffInitialDelay = "1m"
backoffMaxDelay = "2h"
observationSource = """
decode_log [type=ethabidecodelog
abi="RandomnessRequest(bytes32 keyHash,uint256 seed,bytes32 indexed jobID,address sender,uint256 fee,bytes32 requestID)"
data="$(jobRun.logData)"
topics="$(jobRun.logTopics)"]
vrf [type=vrf
publicKey="$(jobSpec.publicKey)"
requestBlockHash="$(jobRun.logBlockHash)"
requestBlockNumber="$(jobRun.logBlockNumber)"
topics="$(jobRun.logTopics)"]
encode_tx [type=ethabiencode
abi="fulfillRandomnessRequest(bytes proof)"
data="{\\"proof\\": $(vrf)}"]
submit_tx [type=ethtx to="%s"
data="$(encode_tx)"
txMeta="{\\"requestTxHash\\": $(jobRun.logTxHash),\\"requestID\\": $(decode_log.requestID),\\"jobID\\": $(jobSpec.databaseID)}"]
decode_log->vrf->encode_tx->submit_tx
"""
`,
assertion: func(t *testing.T, s job.Job, err error) {
require.Error(t, err)
require.True(t, errors.Is(ErrKeyNotSet, errors.Cause(err)))
},
},
{
name: "missing coordinator address",
toml: `
type = "vrf"
schemaVersion = 1
minIncomingConfirmations = 10
fromAddresses = ["0xD883a6A1C22fC4AbFE938a5aDF9B2Cc31b1BF18B"]
publicKey = "0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F8179800"
observationSource = """
decode_log [type=ethabidecodelog
Expand Down Expand Up @@ -129,6 +169,7 @@ decode_log->vrf->encode_tx->submit_tx
type = "vrf"
schemaVersion = 1
minIncomingConfirmations = 10
fromAddresses = ["0xD883a6A1C22fC4AbFE938a5aDF9B2Cc31b1BF18B"]
publicKey = "0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F8179800"
coordinatorAddress = "0xB3b7874F13387D44a3398D298B075B7A3505D8d4"
externalJobID = "0eec7e1d-d0d2-476c-a1a8-72dfb6633f46"
Expand Down Expand Up @@ -162,6 +203,7 @@ decode_log->vrf->encode_tx->submit_tx
type = "vrf"
schemaVersion = 1
minIncomingConfirmations = 10
fromAddresses = ["0xD883a6A1C22fC4AbFE938a5aDF9B2Cc31b1BF18B"]
publicKey = "0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F8179800"
coordinatorAddress = "0xB3b7874F13387D44a3398D298B075B7A3505D8d4"
externalJobID = "0eec7e1d-d0d2-476c-a1a8-72dfb6633f46"
Expand Down Expand Up @@ -196,6 +238,7 @@ decode_log->vrf->encode_tx->submit_tx
schemaVersion = 1
minIncomingConfirmations = 10
requestedConfsDelay = 10
fromAddresses = ["0xD883a6A1C22fC4AbFE938a5aDF9B2Cc31b1BF18B"]
publicKey = "0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F8179800"
coordinatorAddress = "0xB3b7874F13387D44a3398D298B075B7A3505D8d4"
externalJobID = "0eec7e1d-d0d2-476c-a1a8-72dfb6633f46"
Expand Down Expand Up @@ -229,6 +272,7 @@ decode_log->vrf->encode_tx->submit_tx
type = "vrf"
schemaVersion = 1
minIncomingConfirmations = 10
fromAddresses = ["0xD883a6A1C22fC4AbFE938a5aDF9B2Cc31b1BF18B"]
requestedConfsDelay = -10
publicKey = "0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F8179800"
coordinatorAddress = "0xB3b7874F13387D44a3398D298B075B7A3505D8d4"
Expand Down Expand Up @@ -262,6 +306,7 @@ decode_log->vrf->encode_tx->submit_tx
type = "vrf"
schemaVersion = 1
minIncomingConfirmations = 10
fromAddresses = ["0xD883a6A1C22fC4AbFE938a5aDF9B2Cc31b1BF18B"]
requestedConfsDelay = 10
publicKey = "0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F8179800"
coordinatorAddress = "0xB3b7874F13387D44a3398D298B075B7A3505D8d4"
Expand Down Expand Up @@ -296,6 +341,7 @@ decode_log->vrf->encode_tx->submit_tx
type = "vrf"
schemaVersion = 1
minIncomingConfirmations = 10
fromAddresses = ["0xD883a6A1C22fC4AbFE938a5aDF9B2Cc31b1BF18B"]
requestedConfsDelay = 10
requestTimeout = "168h" # 7 days
publicKey = "0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F8179800"
Expand Down Expand Up @@ -331,6 +377,7 @@ decode_log->vrf->encode_tx->submit_tx
type = "vrf"
schemaVersion = 1
minIncomingConfirmations = 10
fromAddresses = ["0xD883a6A1C22fC4AbFE938a5aDF9B2Cc31b1BF18B"]
requestedConfsDelay = 10
batchFulfillmentEnabled = true
publicKey = "0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F8179800"
Expand Down Expand Up @@ -365,6 +412,7 @@ decode_log->vrf->encode_tx->submit_tx
type = "vrf"
schemaVersion = 1
minIncomingConfirmations = 10
fromAddresses = ["0xD883a6A1C22fC4AbFE938a5aDF9B2Cc31b1BF18B"]
requestedConfsDelay = 10
batchFulfillmentEnabled = true
batchCoordinatorAddress = "0xB3b7874F13387D44a3398D298B075B7A3505D8d4"
Expand Down Expand Up @@ -401,6 +449,7 @@ decode_log->vrf->encode_tx->submit_tx
type = "vrf"
schemaVersion = 1
minIncomingConfirmations = 10
fromAddresses = ["0xD883a6A1C22fC4AbFE938a5aDF9B2Cc31b1BF18B"]
publicKey = "0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F8179800"
coordinatorAddress = "0xB3b7874F13387D44a3398D298B075B7A3505D8d4"
requestTimeout = "168h" # 7 days
Expand Down Expand Up @@ -436,6 +485,7 @@ decode_log->vrf->encode_tx->submit_tx
type = "vrf"
schemaVersion = 1
minIncomingConfirmations = 10
fromAddresses = ["0xD883a6A1C22fC4AbFE938a5aDF9B2Cc31b1BF18B"]
publicKey = "0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F8179800"
coordinatorAddress = "0xB3b7874F13387D44a3398D298B075B7A3505D8d4"
requestTimeout = "168h" # 7 days
Expand Down Expand Up @@ -481,6 +531,7 @@ decode_log->vrf->encode_tx->submit_tx
type = "vrf"
schemaVersion = 1
minIncomingConfirmations = 10
fromAddresses = ["0xD883a6A1C22fC4AbFE938a5aDF9B2Cc31b1BF18B"]
publicKey = "0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F8179800"
coordinatorAddress = "0xB3b7874F13387D44a3398D298B075B7A3505D8d4"
requestTimeout = "168h" # 7 days
Expand Down Expand Up @@ -517,6 +568,7 @@ decode_log->vrf->encode_tx->submit_tx
type = "vrf"
schemaVersion = 1
minIncomingConfirmations = 10
fromAddresses = ["0xD883a6A1C22fC4AbFE938a5aDF9B2Cc31b1BF18B"]
publicKey = "0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F8179800"
coordinatorAddress = "0xB3b7874F13387D44a3398D298B075B7A3505D8d4"
requestTimeout = "168h" # 7 days
Expand Down

0 comments on commit 28d0279

Please sign in to comment.