Topics

Build blockchain with timeshift feature #fabric-chaincode

Marek Malik
 

Hello all, 

I have this requirement for test and qat environment to have the possibility to shift the time on the blockchain. For example, today is 13/07/2020, for testing reasons I would like to shift the date to 13/04/2020.
Currently, I developed the feature directly in the chaincode. I check if there is a specific state record that has the fixed DateTime value and I use it to initialize the Clock, otherways I set the Clock instance to the system clock. I enabled storing the fixed clock with a chaincode. This unfortunately makes the time shift code available all the time. 

For safety reasons, this should be only possible in test/qat environments, not production. I'm searching for any solution that I could be using to have this feature disabled on production.
Usually, this kind of feature is toggle switched by env.vars but chaincodes are not able to read custom envs (or so I think so). The only thing that is required is not to include/allow the additional contract methods to set the clock to a fixed value to be used on production.
Does anyone have any idea to restrict this depending on the environment?