def test_builder(): print("inf.cores=", vm.InfVmKeys.names()) b = DemandBuilder() e = datetime.now(timezone.utc) + timedelta(days=1) b.add(props.Activity(expiration=e)) b.add(vm.VmRequest(package_url="", package_format=vm.VmPackageFormat.GVMKIT_SQUASH)) print(b)
async def create_demand_builder(self, expiration_time: datetime, payload: Payload) -> DemandBuilder: """Create a `DemandBuilder` for given `payload` and `expiration_time`.""" builder = DemandBuilder() builder.add( props.Activity(expiration=expiration_time, multi_activity=True)) builder.add(props.NodeInfo(subnet_tag=self._subnet)) if self._subnet: builder.ensure(f"({props.NodeInfoKeys.subnet_tag}={self._subnet})") await builder.decorate(self.payment_decorator, self.strategy, payload) return builder
async def list_offers(conf: Configuration): async with conf.market() as client: market_api = Market(client) dbuild = DemandBuilder() dbuild.add(yp.Identification(name="some scannig node", subnet_tag="testnet")) dbuild.add(yp.Activity(expiration=datetime.now(timezone.utc))) async with market_api.subscribe(dbuild.props, dbuild.cons) as subscription: async for event in subscription.events(): print(f"Offer: {event.id}") print(f"from {event.issuer}") print(f"props {json.dumps(event.props, indent=4)}") print("\n\n") print("done")
async def list_offers(conf: Configuration, subnet_tag: str): async with conf.market() as client: market_api = Market(client) dbuild = DemandBuilder() dbuild.add(yp.NodeInfo( name="Golem Stats Indexer", subnet_tag=subnet_tag)) dbuild.add(yp.Activity(expiration=datetime.now(timezone.utc))) async with market_api.subscribe(dbuild.properties, dbuild.constraints) as subscription: async for event in subscription.events(): if event.props['golem.runtime.name'] != "wasmtime": if event.issuer in str(test): continue else: data = event.props if event.props['golem.runtime.name'] == "gminer": try: data["wallet"] = event.props['golem.com.payment.platform.polygon-polygon-glm.address'] except: data['wallet'] = event.props["golem.com.payment.platform.erc20-polygon-glm.address"] data['golem.node.debug.subnet'] = "Thorg" data['id'] = event.issuer test.append(json.dumps(data)) if event.props['golem.runtime.name'] == "hminer": data['wallet'] = event.props['golem.com.payment.platform.polygon-polygon-glm.address'] data['golem.node.debug.subnet'] = "Thorg" data['id'] = event.issuer test.append(json.dumps(data)) if "golem.com.payment.platform.zksync-mainnet-glm.address" in str(event.props): data['wallet'] = event.props['golem.com.payment.platform.zksync-mainnet-glm.address'] elif "golem.com.payment.platform.zksync-rinkeby-tglm.address" in str(event.props): data['wallet'] = event.props['golem.com.payment.platform.zksync-rinkeby-tglm.address'] elif "golem.com.payment.platform.erc20-mainnet-glm.address" in str(event.props): data['wallet'] = event.props['golem.com.payment.platform.erc20-mainnet-glm.address'] elif "golem.com.payment.platform.erc20-polygon-glm.address" in str(event.props): data['wallet'] = event.props['golem.com.payment.platform.erc20-polygon-glm.address'] elif "golem.com.payment.platform.erc20-rinkeby-tglm.address" in str(event.props): data['wallet'] = event.props['golem.com.payment.platform.erc20-rinkeby-tglm.address'] data['id'] = event.issuer test.append(json.dumps(data))
async def renegotiate_offers(conf: Configuration, subnet_tag: str): """Rejects every proposal & then renegotiates it""" async with conf.market() as client: market_api = Market(client) dbuild = DemandBuilder() dbuild.add( yp.NodeInfo(name="some renegotiating node", subnet_tag=subnet_tag)) dbuild.add( yp.Activity( expiration=datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta(minutes=30))) async with market_api.subscribe(dbuild.properties, dbuild.constraints) as subscription: issuers = set() proposals = 0 rejected_proposals = set() # Already rejected, don't reject again async for event in subscription.events(): node_name = event.props.get("golem.node.id.name") proposal_id = event._proposal.proposal.proposal_id print(f"\n[{node_name}] {'*'*15} {proposal_id}") prev_proposal_id = event._proposal.proposal.prev_proposal_id print(f"[{node_name}] prev_proposal_id: {prev_proposal_id}") if not event.is_draft: if proposals > PROPOSALS_LIMIT: print(f"[node_name] Skipping additional proposal") break await _respond(event, dbuild) proposals += 1 issuers.add(event.issuer) print( f"[{node_name}] Responded. proposals={proposals}, issuers={len(issuers)}" ) continue print( f"[{node_name}] Offer: {proposal_id} from {event.issuer} is_draft: {event.is_draft}" ) if prev_proposal_id not in rejected_proposals: await event.reject() print( f"[{node_name}] Rejected {len(rejected_proposals)}. id: {proposal_id}" ) await asyncio.sleep(1) print(f"[{node_name}] Renegotiating. id: {proposal_id}") new_offer_id = await _respond(event, dbuild) print(f"[{node_name}] new_offer_id: {new_offer_id}") rejected_proposals.add(new_offer_id) continue print(".create_agreement()") agreement = await event.create_agreement() print(".confirm()") confirm_result = await agreement.confirm() print(f"[{node_name}] agreement.confirm(): {confirm_result}") if confirm_result: terminate_reason = { "message": "Work cancelled", "golem.requestor.code": "Cancelled", } terminate_result = await agreement.terminate( terminate_reason) print(f"agreement.terminate(): {terminate_result}") print("All done")