OpenChat Sale Finalization

TLDR: There was a minor issue when finalizing the Sale for the OpenChat SNS. It was quickly identified and fixed, and the OpenChat Sale is now complete.

Context

After a Decentralization Sale, the sale must be finalized. This happens during a call to finalize_swap.

This finalization happens in 5 stages:

  1. Transfer ICP from sale accounts to the main SNS Governance account on the ICP Ledger
  2. Have NNS Governance settle Community Fund participation
  3. Transfer SNS tokens into the Neuron accounts for configured baskets on the SNS Ledger
  4. Create Sale Neurons by calling claim_swap_neurons on SNS Governance
  5. Set SNS Governance to Normal mode.

The Problem

Steps 1-3 all proceeded without any problem, but step 4 immediately failed with an error:

Encountered a CanisterCallError when claiming a batch of neurons. Err: CanisterCallError { code: Some(5), description: "IC0522: Canister 2jvtu-yqaaa-aaaaq-aaama-cai exceeded the instruction limit for single message execution." }

This happened when the claim_swap_neurons endpoint was called with the maximum batch size from the SNS Swap canister, of 11565 NeuronRecipes.

This problem did not arise during testing, and we are working on identifying the underlying reason why it did not show up in test environments.

The Fix

The solution was to reduce the amount of work done in each request.

This was accomplished by changing the following lines in rs/sns/swap/src/swap.rs

let neuron_parameters_size = mem::size_of::<NeuronParameters>();
let batch_limit =  
    CLAIM_SWAP_NEURONS_MESSAGE_SIZE_LIMIT_BYTES.saturating_div(neuron_parameters_size);

to instead be:

let batch_limit = 500_usize;

In order to ensure no data would be lost, we reproduced a sale in progress in a test environment with a large number of neurons, performed an upgrade to the new version, and finalized successfully.

The changes made were minimal, but we still wanted to be extremely cautious in making changes to a live Sale canister pre-finalization.

Sale canisters are controlled by the NNS root canister. We therefore submitted an NNS proposal to upgrade the sale canister.

You can see the proposal, and below are links to the two commits referenced in the proposal.

Add logging for finalize_swap
Merge branch ‘fixed-batch-length’ into 'master

Conclusion

After the propsal was adopted, finalize_swap was re-run, which immediately resulted in a successful close of the sale.

OpenChat has been successfully decentralized! :tada:

15 Likes

Great to hear that the minor issue during the OpenChat SNS Sale finalization has been swiftly identified and resolved! It’s commendable that the team took a cautious approach by reducing the batch size to ensure a smooth process.

The proactive testing in a controlled environment and the careful upgrade via an NNS proposal demonstrate a commitment to maintaining the integrity of the live Sale canister pre-finalization. The transparency in sharing the process, along with the links to the relevant commits, provides valuable insights into the troubleshooting steps taken.

Congratulations on the successful decentralization of OpenChat! It’s a testament to the team’s dedication and adaptability in overcoming unforeseen challenges. Looking forward to seeing how the decentralized OpenChat community continues to evolve. Well done!
Thanks for sharing . OpenChat Sale Finalizationclick here

1 Like

Thanks for sharing these insights mate.