I set VRF chainLink fee on 0.1 LINK instead of 2 LINK on mainnet, how to fix this issue? (already deploy) - chainlink

We have deployed the VRF contract on mainnet and we added it to our main contract.
But there is issue, we set the fee limit for 0.1 LINK instead of 2 LINK, and now it look like it’s doesn’t work.
Can you give us the solution for this issue.
constructor ()
VRFConsumerBase(
0xf0d54349aDdcf704F77AE15b96510dEA15cb7952, // VRF Coordinator
0x514910771AF9Ca656af840dff83E8264EcF986CA// LINK Token
)
{
keyHash = 0xAA77729D3466CA35AE8D28B3BBAC7CC36A5031EFDC430821C02BC31A238AF445;
**fee = 0.1 * 10 ** 18; // 0.1 LINK**
}

Your only solution here is to redeploy your contracts with the correct fee set.
Code deployed to a blockchain is immutable, and since you have hardcoded the fee in it can't be changed. In the future, you could always create a setter function that can only be accessed by the contract owner that allows you to change the fee. An example:
function setFee(uint256 _fee) public onlyOwner {
fee = _fee;
}
This function uses the OpenZeppelin Ownable contract to get the onlyOwner modifier.

Related

PKCS11 does not recognize new slot created in softhsm in runtime

I have a piece of code to import key and certificate into hsm using java. The problem is that when I run the java back-end to execute that api, it is ok when using the slots which were created before. However the problem here, when I create new slot at that time and try to execute the api for that slot, I received the message that show the slot id not found.
How do I achieve the result without re-running the code ? Here is what I am doing
public void importCertAndPk(String pin, String slotId, String alias, InputStream p12File) {
Provider p = getProvider(slotId);
// Load the key store
KeyStore ks = getKeyStore(p, pin);
BouncyCastleProvider provider = new BouncyCastleProvider();
// Get pk and cert from p12 file
KeyStore pkcs12KeyStore = KeyStore.getInstance("pkcs12", provider.getName());
pkcs12KeyStore.load(p12File, System.getenv("P12_PASS").toCharArray());
String pkcs12Alias = pkcs12KeyStore.aliases().nextElement();
PrivateKey pk = (PrivateKey) pkcs12KeyStore.getKey(pkcs12Alias, null);
Certificate[] chain = pkcs12KeyStore.getCertificateChain(pkcs12Alias);
ks.setKeyEntry(alias, pk, pin.toCharArray(), chain);
}
When I re-run the back-end code again, it works
Please look at PKCS#11 specification section 5.5:
Furthermore, the set of slots accessible through a Cryptoki library is
checked at the time that C_GetSlotList, for list length prediction
(NULL pSlotList argument) is called. If an application calls
C_GetSlotList with a non-NULL pSlotList, and then the user adds or
removes a hardware device, the changed slot list will only be visible
and effective if C_GetSlotList is called again with NULL
You must re-query slot's list.

Chainlink VRF very slow - 20+ minutes for response to fulfillRandomness on Rinkeby

I have implemented a basic Chainlink VRF function in Solidity and deployed to Ethereum test network Rinkeby
function getRandomNumber() public returns (bytes32 requestId)
{
require(LINK.balanceOf(address(this)) >= fee, "Not enough LINK");
return requestRandomness(keyHash, fee);
}
function fulfillRandomness(bytes32 requestId, uint256 randomness) internal override
{
randomResult = randomness;
_requestId = requestId;
}
This works fine, deducts the LINK fee from my wallet, and eeeeeventually does call back fulfillRandomness with a random hex value, however it takes forever!
Just did a test and it took 30 minutes. Could I be doing something wrong or why is it taking so long? I know it's async and there's lots of stuff going on to fetch the random number, but at these speeds it's basically unusable right
The Rinkeby testenet has had some downtime issues this weekend. You can use the Kovan testnet and VRF until Rinkeby is operating normally again.
I switched to Kovan and I'm reliably getting ~1 min VRF responses

querying data with micrometer

We have this fancy monitoring system to which our spring-boot services are posting metrics to an influx DB with micrometer. There's a nice grafana frontend, but the problem is that we're now at a stage where we have to have some of these metrics available in other services to reason on.
The whole system was set up by my predecessor, and my current understanding of it is practically zero. I can add and post new metrics, but I can't for the life of me get anything out of it.
Here's a short example:
Our gateway increments the counter for each image that a camera posts to it. The definition of the counter looks like this:
private val imageCounters = mutableMapOf<String, Counter>()
private val imageCounter = { camera: String ->
imageCounters.getOrPut(camera) {
registry.counter("gateway.image.counter", "camera", camera)
}
And the counter is incremented in the code like this:
imageCounter("placeholder-id").increment()
Now we're improving our billing, and the billing service needs to know how many images for a certain camera went through the gateway. So naturally the first thing I try looks like this:
class MonitoringService(val metrics: MeterRegistry) {
private val log = logger()
private val imageCounters = mutableMapOf<String, Counter>()
private val imageCounter = { camera: String ->
imageCounters.getOrPut(camera) {
metrics.counter("gateway.image.counter", "camera", camera)
}
}
fun test() {
val test = imageCounter("16004").count()
val bugme = true
log.info("influx test: $test")
}
}
There's two problems with this: First off it always returns zero, so obviously I'm doing it wrong. I just can't figure out what it is.
Second, even if it would return a reasonable value, I don't see a way to limit this by time (I'll usually need the number of images uploaded during the current month).
What worries me is that while I can find a lot of documentation on how to post data with micrometer, I can't seem to find any documentation on how to query. Is Micrometer only designed to post monitoring data, but not query it? the .getOrPut() method would indicate it can do both, but since querying data seems undocumented as far as I can tell, that might be a misconception on my part.
There is an influx-db client for Java, which I'll try next, but at the end of the day I don't want multiple components in my application doing the same thing just because I'm not familiar with the tools I inherited.
InfluxMeterRegistry is a StepMeterRegistry, so the created Counter from it is a StepCounter. StepCounter.increment() increments the count in the current step but StepCounter.count() will return the count in the previous step. That's why you're seeing 0 with count() although you've already invoked increment() several times. You can see it in the next step and the default step is 1 minute, so you have to wait for 1 minute to see it.
See the following test to get an idea on how it works: https://github.com/izeye/sample-micrometer-spring-boot/blob/influx/src/test/java/com/izeye/sample/InfluxMeterRegistryTests.java

Magento: Is Tablerate Shipping based on the cart sum with or without taxes?

I have a Shop with Products that have different Taxrates. Some have 0%, some 19% etc...
For Shipping im using Tablerates, for example:
up to 2000€ = 10€ shipping cost
up to or over 2400€ = 15€ shipping cost
Now comes the thing that at first i just want to understand, so there is not really a bug to fix here. I just need to know how it works to plan my tablerates accordingly.
I have orders with a total over 2400€ (incl. Tax), but the customer still gets the 10€ Shipping rate. This can only be if the System is using the Price without Tax to check against the table rates. Because only then would the price be in the Tablerate range for the lower rate. And yes i double checked the Tablerates Setup (not my first Magento Install).
1) Is this assumption correct that table rates are checked against the total without taxes?
2) Is there a way to set up tablerates to check against the cart total including taxes?
Anyone got any info on how that works in the background? I couldnt find anything as when youre searching the topic you mostly get tutorial on how to set up table rates.
Super thankful for any tipps or maybe other threads or places i could check for detailed infos on how that works.
note: i use Magento 1.9.2.1
For Question 1:
It would appear to be without tax.
Mage_Shipping_Model_Shipping::collectRatesByAddress calls setPackageValue to set the package value for the rate request.
This gets passed to Mage_Shipping_Model_Carrier_Tablerate::collectRates.
collectRates subtracts free shipping from the package value.
Then Mage_Shipping_Model_Carrier_Tablerate::getRate is called
$result = Mage::getModel('shipping/rate_result');
$rate = $this->getRate($request);
...
public function getRate(Mage_Shipping_Model_Rate_Request $request)
{
return Mage::getResourceModel('shipping/carrier_tablerate')->getRate($request);
}
This calls Mage_Shipping_Model_Resource_Carrier_Tablerate::getRate which binds the condition value to the query. (The condition name should be package_value in your case).
// Render condition by condition name
if (is_array($request->getConditionName())) {
$orWhere = array();
$i = 0;
foreach ($request->getConditionName() as $conditionName) {
$bindNameKey = sprintf(':condition_name_%d', $i);
$bindValueKey = sprintf(':condition_value_%d', $i);
$orWhere[] = "(condition_name = {$bindNameKey} AND condition_value <= {$bindValueKey})";
$bind[$bindNameKey] = $conditionName;
$bind[$bindValueKey] = $request->getData($conditionName);
$i++;
}
if ($orWhere) {
$select->where(implode(' OR ', $orWhere));
}
} else {
$bind[':condition_name'] = $request->getConditionName();
$bind[':condition_value'] = $request->getData($request->getConditionName());
$select->where('condition_name = :condition_name');
$select->where('condition_value <= :condition_value');
}
While it is possible to modify the order, baseSubtotal should be before tax.
See collectRatesByAddress:
$request->setBaseSubtotalInclTax($address->getBaseSubtotalInclTax()
+ $address->getBaseExtraTaxAmount());
As for your question 2.
As noted above, we have the data in the request, but we do not have an easy touchpoint.
One suggestion is to rewrite the Mage_Shipping_Model_Carrier_Tablerate and override getRate. What you would do would be to set the BaseSubtotal to the BaseSubtotalInclTax, call parent, then reset the request.
public function getRate(Mage_Shipping_Model_Rate_Request $request)
{
// TODO: wrap in try catch, to reset the value ??
// TODO: clone the request ??
// TODO: Test This
$oldPackageValue = $request->getPackageValue();
$request->setPackageValue($request->getBaseSubtotalInclTax());
$returnvalue = Mage::getResourceModel('shipping/carrier_tablerate')->getRate($request);
$request->setPackageValue($oldPackageValue);
return $returnvalue;
}
This is hacky, but minimally intrusive. It should withstand unrelated changes without forcing you to modify the code.
Another method involves rewriting and modifying Mage_Shipping_Model_Resource_Carrier_Tablerate::getRate to use the value you want.
NOTE: Neither of these methods are tested.

getRate() and Magento tax percentage

I'm trying to get the tax rate (percentage, not currency) for a given postcode so I can display it in a third-party quote PDF printout (no relation to the "quote" Magento uses as the shopping cart pre-checkout). While I'm still relatively new to Magento it appears that getRateRequest() and getRate() are the two main functions which get the tax rate based on all the variables (product tax class, customer tax class, etc.).
Since this is for a third-party extension and all our products are taxable I figured I would just use getRate() with the correct Varien Object input and it would return the tax rate. After a week of trial and error I can't figure out why I'm always getting a rate of zero. I've confirmed I'm calling the getRate() function and that it's not returning zero from the first if() statement checking for Country and Customer/Product class ID. In addition I've confirmed all the variables are being passed on and accessible in the getRate() function itself.
I've created an object with the below input (based on the output of getRateRequest()) that I call with getRate() and am hoping someone can shed light on what is wrong with my data input or why the getRate() function is always returning a result of zero. (I'm actually setting with $variables below, they are just defined earlier up and one of my test case values are below)
// UPDATED CODE (variable values come from 3rd party quote extension)
$country = 'US'; // use short country code
$region = '12'; // must be numeric!
$postcode = '95050';
// our quote extension stores the customer id ('2') which we use to get the tax class
$customer = Mage::getModel('customer/customer')->load( '2' );
$custTax = $customer->getTaxClassId();
$TaxRequest = new Varien_Object();
$TaxRequest->setCountryId( $country );
$TaxRequest->setRegionId( $region );
$TaxRequest->setPostcode( $postcode );
$TaxRequest->setStore( Mage::app()->getStore() );
$TaxRequest->setCustomerClassId( $custTax );
$TaxRequest->setProductClassId(2); // 2=taxable id (all our products are taxable)
$taxCalculationModel = Mage::getSingleton('tax/calculation');
$rate = $taxCalculationModel->getRate($TaxRequest);
My backup plan is to just do a direct SQL lookup formula although that will probably get a bit messy. Since our web development team didn't exactly follow good coding standards an eventual site re-write is in my future anyway once the initial launch fixes are in (all 4 pages of them).
Thanks for any help and taking the time to read this.
EDIT - Stack Overflow is awesome :)
You can also try this
$store = Mage::app()->getStore('default');
$request = Mage::getSingleton('tax/calculation')->getRateRequest(null, null, null, $store);
$taxclassid = $product->getData('tax_class_id');
$percent = Mage::getSingleton('tax/calculation')->getRate($request->setProductClassId($taxclassid));
If you change:
$TaxRequest->setRegionId(California);
to
$TaxRequest->setRegionId($stateId);
where $stateId is numeric region id. Your code should work then.

Resources