rwth-acis / las2peer

A Java-based decentralized framework for distributing community services in a peer-to-peer infrastructure.
https://las2peer.org
Other
52 stars 13 forks source link

Problem storing Ethereum agents #70

Closed AlexanderNeumann closed 3 years ago

AlexanderNeumann commented 3 years ago

Sometimes the Blockchain gets out of sync with the number of transactions for a wallet and new entries fail. I think it is related to faulty contracts that just fail.. (e.g. service registration of services which are not compatible with the current blockchain implementation).

As a workaround we have different wallets for the contract types (faulty ones like service registrations and user related contracts) In our setup:

> eth.getTransactionCount("0xb5a66d27457af8be2a09f17add73c2ae46520e69")
8
> eth.getTransactionCount("0x547d11bb78efd735f562cfeeb48d28854c98e98d")
30092
> eth.getTransactionCount("0x00a0d82533ec22ba23f8b894cda1873def8342e3")
69

related console log:

Failed to register EthereumAgent; error: i5.las2peer.registry.exceptions.EthereumException: java.util.concurrent.ExecutionException: org.web3j.tx.exceptions.ContractCallException: Empty value (0x) returned from contract
i5.las2peer.api.security.AgentException: Problem storing Ethereum agent
    at i5.las2peer.p2p.EthereumNode.storeAgent(EthereumNode.java:190)
    at i5.las2peer.connectors.webConnector.util.AuthenticationManager.createNewOidcAgent(AuthenticationManager.java:292)
    at i5.las2peer.connectors.webConnector.util.AuthenticationManager.authenticateOIDC(AuthenticationManager.java:152)
    at i5.las2peer.connectors.webConnector.util.AuthenticationManager.authenticateAgent(AuthenticationManager.java:78)
    at i5.las2peer.connectors.webConnector.WebConnector.authenticateAgent(WebConnector.java:658)
    at i5.las2peer.connectors.webConnector.WebConnectorRequestHandler.authenticate(WebConnectorRequestHandler.java:173)
    at i5.las2peer.connectors.webConnector.WebConnectorRequestHandler.handle(WebConnectorRequestHandler.java:147)
    at i5.las2peer.connectors.webConnector.WebConnectorRequestHandler.handleGET(WebConnectorRequestHandler.java:119)
    at sun.reflect.GeneratedMethodAccessor77.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:81)
    at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:144)
    at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:161)
    at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$ResponseOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:160)
    at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:99)
    at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:389)
    at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:347)
    at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:102)
    at org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:326)
    at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
    at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:267)
    at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317)
    at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:305)
    at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1154)
    at org.glassfish.jersey.jdkhttp.JdkHttpHandlerContainer.handle(JdkHttpHandlerContainer.java:161)
    at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:79)
    at sun.net.httpserver.AuthFilter.doFilter(AuthFilter.java:83)
    at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:82)
    at sun.net.httpserver.ServerImpl$Exchange$LinkHandler.handle(ServerImpl.java:675)
    at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:79)
    at sun.net.httpserver.ServerImpl$Exchange.run(ServerImpl.java:647)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Caused by: i5.las2peer.registry.exceptions.EthereumException: java.util.concurrent.ExecutionException: org.web3j.tx.exceptions.ContractCallException: Empty value (0x) returned from contract
    at i5.las2peer.registry.ReadOnlyRegistryClient.usernameIsAvailable(ReadOnlyRegistryClient.java:179)
    at i5.las2peer.p2p.EthereumNode.registerAgentInBlockchain(EthereumNode.java:203)
    at i5.las2peer.p2p.EthereumNode.storeAgent(EthereumNode.java:186)
    ... 37 more
Caused by: java.util.concurrent.ExecutionException: org.web3j.tx.exceptions.ContractCallException: Empty value (0x) returned from contract
    at java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:357)
    at java.util.concurrent.CompletableFuture.get(CompletableFuture.java:1895)
    at i5.las2peer.registry.ReadOnlyRegistryClient.usernameIsAvailable(ReadOnlyRegistryClient.java:177)
    ... 39 more
Caused by: org.web3j.tx.exceptions.ContractCallException: Empty value (0x) returned from contract
    at org.web3j.tx.Contract.executeCallSingleValueReturn(Contract.java:246)
    at org.web3j.tx.Contract.lambda$executeRemoteCallSingleValueReturn$1(Contract.java:313)
    at org.web3j.protocol.core.RemoteCall.send(RemoteCall.java:30)
    at org.web3j.utils.Async.lambda$run$26(Async.java:27)
    at java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1626)
    ... 3 more
Internal Server Error: OIDC agent creation failed
erdzan12 commented 3 years ago

### Reproduction steps for the issue:

Create a las2peer main bootstrap deployment (with las2peer version 1.1.1) and a ethnet for las2peer with following example config files. Finally bootstrap a las2peer service which tries to announce its deployment, like with the config file below.

las2peer main bootstrap deployment

```yaml kind: Deployment apiVersion: apps/v1 metadata: name: las2peer-bootstrap namespace: YOUR_NAMESPACE spec: replicas: 1 selector: matchLabels: io.kompose.service: las2peer-bootstrap template: metadata: creationTimestamp: null labels: io.kompose.service: las2peer-bootstrap spec: volumes: - name: node-info-volume configMap: name: node-info defaultMode: 420 containers: - name: las2peer image: registry.tech4comp.dbis.rwth-aachen.de/rwthacis/las2peer ports: - containerPort: 9000 protocol: TCP - containerPort: 8080 protocol: TCP - containerPort: 8001 protocol: TCP env: - name: LAS2PEER_ETH_HOST value: las2peer-ethnet:8545 - name: NODE_ID_SEED value: '1' - name: LAS2PEER_PORT value: '9000' resources: {} volumeMounts: - name: node-info-volume mountPath: /app/las2peer/etc/nodeInfo.xml subPath: nodeInfo.xml livenessProbe: httpGet: path: /las2peer/webapp/welcome port: 32010 host: 137.226.232.175 scheme: HTTP initialDelaySeconds: 300 timeoutSeconds: 180 periodSeconds: 300 successThreshold: 1 failureThreshold: 1 terminationMessagePath: /dev/termination-log terminationMessagePolicy: File imagePullPolicy: Always restartPolicy: Always terminationGracePeriodSeconds: 30 dnsPolicy: ClusterFirst securityContext: {} affinity: nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: nodeSelectorTerms: - matchExpressions: - key: kubernetes.io/hostname operator: In values: - tech4compslave2 schedulerName: default-scheduler strategy: type: RollingUpdate rollingUpdate: maxUnavailable: 25% maxSurge: 25% revisionHistoryLimit: 10 progressDeadlineSeconds: 600 ```

ethnet deployment

```yaml kind: Deployment apiVersion: apps/v1 metadata: name: las2peer-ethnet namespace: YOUR_NAMESPACE spec: replicas: 1 selector: matchLabels: io.kompose.service: las2peer-ethnet template: metadata: creationTimestamp: null labels: io.kompose.service: las2peer-ethnet spec: containers: - name: ethereum image: tjanson/go-ethereum:monitored-client ports: - containerPort: 30303 protocol: TCP - containerPort: 30303 protocol: UDP - containerPort: 8545 protocol: TCP - containerPort: 8546 protocol: TCP env: - name: GETH_VERBOSITY value: '1' resources: {} terminationMessagePath: /dev/termination-log terminationMessagePolicy: File imagePullPolicy: IfNotPresent restartPolicy: Always terminationGracePeriodSeconds: 30 dnsPolicy: ClusterFirst securityContext: {} affinity: nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: nodeSelectorTerms: - matchExpressions: - key: kubernetes.io/hostname operator: In values: - tech4compslave2 schedulerName: default-scheduler strategy: type: RollingUpdate rollingUpdate: maxUnavailable: 25% maxSurge: 25% revisionHistoryLimit: 10 progressDeadlineSeconds: 600 ```

las2peer service doing service deployment announcements

```yaml kind: Deployment apiVersion: apps/v1 metadata: name: las2peer-bootstrap-2 namespace: YOUR_NAMESPACE spec: replicas: 1 selector: matchLabels: io.kompose.service: las2peer-bootstrap-2 template: metadata: creationTimestamp: null labels: io.kompose.service: las2peer-bootstrap-2 spec: volumes: - name: node-info-volume configMap: name: node-info defaultMode: 420 containers: - name: las2peer image: erdzan12/mycodegen ports: - containerPort: 9000 protocol: TCP - containerPort: 8080 protocol: TCP - containerPort: 8001 protocol: TCP env: - name: HTTP_PORT value: '8080' - name: HTTPS_PORT value: '8443' - name: LAS2PEER_PORT value: '9011' - name: SERVICE_PASSPHRASE value: someNewPass - name: GIT_USER value: someuser - name: GIT_PASSWORD value: shajbdhasbdsajhdsajhbdsad - name: TOKEN value: jkasndhjsbadjhsabdsahb - name: GIT_USER_MAIL value: jhsabdhjabsdbhsa@ajhsbdsahjbdashjb.com - name: GIT_ORGANIZATION value: CAETESTRWTH - name: TEMPLATE_REPOSITORY value: CAE-Templates - name: DEPLOYMENT_REPO value: CAE-Deployment-Temp - name: JENKINS_URL value: https://cae-dev.tech4comp.dbis.rwth-aachen.de/jenkins - name: JENKINS_JOB_TOKEN value: 1235f18c-561d-4c6b-8ffa-4ddmnssjbdahhjbea - name: BUILD_JOB_NAME value: Build-Job - name: DOCKER_JOB_NAME value: Docker-Job - name: USED_GIT_HOST value: GitHub - name: BASE_URL value: https://github.com - name: WIDGET_HOME_BASE_URL value: https://CAETESTRWTH.github.io/ - name: OIDC_PROVIDER value: https://api.learning-layers.eu/o/oauth2 - name: LAS2PEER_CONFIG_ENDPOINT value: las2peer-bootstrap:8001 - name: LAS2PEER_BOOTSTRAP value: las2peer-bootstrap:9000 - name: LAS2PEER_ETH_HOST value: las2peer-ethnet:8545 - name: NODE_ID_SEED value: '2' - name: LAS2PEER_PORT value: '9000' resources: {} volumeMounts: - name: node-info-volume mountPath: /app/las2peer/etc/nodeInfo.xml subPath: nodeInfo.xml terminationMessagePath: /dev/termination-log terminationMessagePolicy: File imagePullPolicy: Always restartPolicy: Always terminationGracePeriodSeconds: 30 dnsPolicy: ClusterFirst securityContext: {} affinity: nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: nodeSelectorTerms: - matchExpressions: - key: kubernetes.io/hostname operator: In values: - tech4compslave2 schedulerName: default-scheduler strategy: type: RollingUpdate rollingUpdate: maxUnavailable: 25% maxSurge: 25% revisionHistoryLimit: 10 progressDeadlineSeconds: 600 ```

After a couple of unsuccessful service announcement attempts the user registration is not possible due to the unsynchronised nonce local nonce and the actual nonce of the account used.

### Proposed fix:

Therefore, the fix in the branch issue-70-nonce-out-of-syn tries to synchronise the nonce, allowing user registration to be possible.