Off-Chain Worker
The offchain workers is a special function of the runtime that gets executed after block is imported. During execution it's able to asynchronously submit extrinsics that will either be propagated to other nodes or added to the next block produced by the node as unsigned transactions.
The Smart Streaming Platforms contain a front-end and a centralized database where the streams are reported. The offchain worker will retrieve the stream reports and return a confirmation message for every row so that it isn't picked up in the next block.
The offchain worker will further process the stream reports and make user-centric calculations. Below is an example where a user-centric royalty calculation is performed on stream reports fetched from an SSP database over 24 hours:
3 attributes are fetched for writing the off-chain worker: User_ID, Track_ID, Stream_Duration. The following steps are applied to arrive at the result: 1) Sort by the all User_Id 2) Calculate the total duration per user 3) Sort the list in decreasing order of total_duration per user. 4) Find the median. Assign upper 50% users with weight 1. 5) From the remaining list (50% values), calculate the median and assign the weight 0.5 to users. 6) From the remaining list (25% of total values), calculate the median and assign the weight 0.25 to the users. 7) Do the following calculations: Reward Pool Balance = 4745 $POLM $POLM daily reward pool = 4745/365= 13 $POLM Active users (in past 24 hrs) = 10 active users (with weight 1), 5 active users with weight 0.5 and 2 active users with weight 0.25 Quota for each user = daily reward pool/active users = 13/(101+50.5+20.25) = 13/13 = 1 $POLM Process stream report: User A ( weight 1) heard total 10 tracks - 1/10 $POLM per track User B (weight 0.5) heard 5 tracks - 0.5/5 $POLM per track User C (weight 0.25) heard 5 tracks (of shorter duration) - 0.25/5 $POLM per track For Track 1 - user A (with weight 1) heard once, user B (with weight 0.5) heard once, and user C (with state 0.25) heard it two times, hence Track 1 will fetch -- 1/10+0.5/5+ 0.252/5 $POLM = 0.3 $POLM
Copy link